How can I access cancan helpers from within cells - cancan

Hey! How can I use the cancan helpers like can? and cannot? from within cells views?

Related

How to change class dynamically for view controller using interface builder

there are different conditions for same design file. i can't use if-else in same class file to differentiate them. because manage all conditions are difficult. is there any way to change class at dynamic time.
Yes, we can set class using Xib. But from my research i didn't find any way to change storyboard class dynamically. I found other way to reuse the view like using container view. following link shows how can we reuse storyboard view.
Diego Lavalle describe it on medium.
and you can read about container view at here.
I think you can use a master view controller and can load different view controllers as child based on some condition.
For example in Master View controller you can use UIsegmentedControl and based on the option the user chooses, you can show different view controllers.
Refer the following for implementing the same.
https://medium.com/#Dougly/creating-a-custom-view-controller-navigation-interface-programmatically-swift-3-1-8c9e582cdb30

TableView in ViewController instead of TableViewController for Datan| Parse.com

I am using Swift with Parse.com. I have a bridging header so I presume that I can use objective-C within the swift project, but I get errors sometimes, so I want to make sure that I am using the two languages correctly within the same project.
I remain unclear how I can use tableView to load information from Parse instead of using the tableViewController for added customization. I would like to be able to use the needed methods within the view controller that contains the tableView object, and reload that information to populate that element.
I need to an update on the requirements of proper classes and if I need to subclass, and how. I have generated my own class for the view controller and connected the tableView object, but I remain unclear how I can call the methods from a normal tableviewcontroller, or if I can simply place the needed methods within the view controller. I am learning about the PFClasses and which ones are needed for the functions that are required.
I currently remain unclear about the communication of the delegates, datasource, and other related items in this arrangement. I am completing project. I am still new to objective-C and have not memorized all of the methods and such, so I am still learning.
It is possible to use a plain UIViewController and have a manual UITableView instead of using a UITableViewController. If you do this, you need to make sure that your UIViewController implements the UITableViewDataSource and UITableViewDelegate protocols.
If you are using IB, you also need to make sure you hook up your custom UITableView class to the proper outlets; or you can create your views in code. That's up to you.
Now for parse specific data, what you can do is you can process your parse.com data in a variety of ways; in response to a UI gesture, when the table loads, or in the background. Either way, once you have the parse data loaded, you just need to make sure your UITableView responds correctly in numberOfRows and cellForRowAtIndexPath.
If you get started and have specific questions, feel free to ask more. But in short, yes, it is possible. I actually prefer this over using UITableViewController because it gives me more flexibility. I in general to not use IB.

Custom UIView from Interface Builder

I'm trying to keep things organized and create hierarchy of views for my app.
So for instance I want to create a custom view to display some text, another custom view to display progress and then use all those views in the main view created with View-Based Application template.
I know how to create it programmatically - you create UIView subclass, implement drawRect method, place an empty UIView in Interface Builder and chance it's Class to my custom class. My problem is that I want to create those custom view's in Interface Builder instead programmatically.
So far I've created UIViewController controller with XIB file and in viewDidLoad method of view controller from the template I create that custom view controller instance and add it's view as a subview of that empty UIView added in Interface Builder (the same you would change Class in programmatic approach).
It works, but it's more of a hack for me and it's hard for me to believe that there isn't a better method where I could add those custom views in interface builder without having to implement viewDidLoad method and create controllers and add their views inside of that method.
This was originally a comment in Ratinho's thread, but grew too large.
Although my own experience concurs with everything mentioned here and above, there are some things that might ease your pain, or at least make things feel a little less hack-ish.
Derive all of your custom UIView classes from a common class, say EmbeddableView. Wrap all of the initWithCoder logic in this base class, using the Class identity (or an overloadable method) to determine the NIB to initialize from. This is still a hack, but your at least formalizing the interface rules and hiding the machinery.
Additionally, you could further enhance your Interface Builder experience by using "micro controller" classes that pair with your custom views to handle their delegate/action methods and bridge the gap with the main UIViewController through it's own delegation protocol. All of this can be wired together using connectors within Interface Builder.
The underlying UIViewController only needs to implement enough functionality to satisfy the "micro controller" delegation pattern.
You already have the details for adding the custom views by changing the class name and handling the nib loading. The "micro controllers" (if used) can just be NSObject derived classes added to the NIB as suggested here.
Although I've done all of these steps in isolated cases, I've never taken it all the way to this sort of formal solution, but with some planning it should be fairly reliable and robust.
For this to work, you have to create a plug-in for Interface Builder that uses your custom control's class. As soon as you create and install your plug-in, you will be able to add by drag and drop, instances of your view onto another window or view in Interface Builder. To learn about creating IB Plugins, see the Interface Builder Plug-In Programming Guide and the chapter on creating your own IB Palette controls from Aaron Hillegass's book, Cocoa Programming for Mac OS X.
Here is the link to the original author of the accepted answer to a similar question.
Maybe i didnt understand u?
you have library in the Interface builder u can move every component u want and place it on your view. (u can add another view by adding UIView and change its class name in the 4th tab).
then u declare vars with IBOutlet and connect them from the 2nd tab of ur file's owners to their components...another question?
Unfortunately, you can't do what you want to do with UIKit. IB Plugins only work for OS X, and Apple explicitly doesn't allow them for use with iOS development. Something to do with them not being static libraries. Who knows, they may change this someday, but I wouldn't hold your breath.

iPhone UITableViewController custom layout

I'm a beginner in iPhone programing. My first app is a UITableViewController but now I would like to experiment a little bit. The idea is to create a custom layout that would look like this:
The layout:
---------------------
Image | Button
---------------------
UICalendar
---------------------
UITableView
---------------------
Button | Button
---------------------
QUESTION 1:
As you can see I would like to add some additional UI elemnts. All the tutorials I've seen describe UITableViewController as a single UITableView (no other UI elements included in a controller).
So my question would be is it possible to extend UITableViewController to have that kind of layout? What is a proper way to do it?
QUESTION 2:
For UITableViewController I don't use XIB file but some people do. Why would I use XIB file when creating a UITableViewController? What are the benefits? What is the best practice?
UPDATE:
Actually what I'm thinking of is to have a separated controller for UICalendar (UICalendarController) and UITableView (UITableViewController). I just don't know how to implement that.
Thx.
The standard approach for the kind of thing you're trying to do is not to subclass UITableViewController or to use a XIB file to define the interface for the view connected with a UITableViewController, but instead to use a UIViewController with a XIB file that happens to include a UITableView in it.
You'll have to implement the UITableViewDataSource and UITableViewDelegate protocols in your UIViewController subclass, but this is not difficult.
UITableViewController is a somewhat brittle and limited class, unfortunately. It's not hard to create your own classes that use UITableViews, but it's unintuitive to many people that the right approach to doing so doesn't start with UITableViewController.
Check out the Tapku library. It comes complete with a Calendar / Table.
In iPhone, you can create every control by programming or you can use XIB. XIB makes the work simple by using native features of the control. If you want to extend the control and its features, create custom classes and create them manually.
Coming to UITableView, is your representation for one cell? Else you can create custom cells and add them to the table view. For creating custom table view cells you have to extend your class from UITableViewCell and implement them.

How to separate view from controller without using interface builder

I want to create UI elements programmatically without using xib files. All of the examples I have found (UICatalog, ...) are creating UI elements directly in the controller methods. What is the best practice to keep up with MVC patternn and separate views from controllers?
Thanks
If I understand the problem correctly, all you have to do is to create a separate view class that will take care of creating the UI elements. Then in the controller class you simply create an instance of the view class.
zoul is correct in his answer. To aid you in doing this, these is a tool that will convert an XIB to the same Objective-C code it would take to create the view:
http://arstechnica.com/apple/guides/2009/04/iphone-dev-convert-xib-files-to-objective-c.ars