Add attributes for UITableViewController - ios

I'm developing a custom class.
The goal is user will add a UITableViewController to the storyboard and set its class to mine.
and my class will fill the tableView.
Here's my question: I want to give the user to set some attributes like header color, etc in storyboard, but #IBdesignable can't be used for UITableViewController
Any idea?

I think the easiest solution is to subclass a UITableView instead of UITableViewController.

Related

Can't assign custom UITableViewCell within custom UIViewController

In my storyboard, if I have a UIViewController that inherits from a custom class, can I create a custom class for a UITableViewCell within a tableview inside that UIViewController?
I've tried to do the above, but when I try to connect outlets, I can only drag to the parent ViewController file, and not to the connected TableViewCell file. Why is that?
You can connect outlets of your cell.
You need to assign the class of custom table view cell in storyboard.
Select the table view cell while dragging to connect outlets.
You seem to be asking 2 questions:
"can I create a custom class for a UITableViewCell"?
Yes, you can use a custom class for your UITableViewCell. Simply select the cell and in the class inspector, enter the custom class.
"I can only drag to the parent ViewController"
That's also correct. For static cells, you can link them to outlets in the view controller. Note that for dynamic cells, you'll need to create them in the tableView:cellForRowAtIndexPath: method.

Custom UITableViewController issue

So I created a subclass of UITableViewController and have the xib,h,m files for this controller. but when I add a UIView or a UITableViewController to my main.storyboard it will not let me set my new subclass as the custom class.
Ive been trying to get this working for about 3 days now, watching youtube videos, reading tutorials and I can't seem to find anything similar to what Im trying to do.
Im trying to create a table with header and search bar that has everything self contained, including datasets.
Make sure your class is a subclass of UITableViewController When you set it as the custom class of an UITableViewController object in the storyboard.
1: MySubClassOfTableViewController is a subclass of UITableViewController
2: Find the UITableViewController object in the storyboard
3: Set Custom Class of the UITableViewController object to MySubClassOfTableViewController

trying to hook up UILabels and IBActions in a custom class (Xcode 5)

I am having issues making UILabels and IBAction buttons in custom classes. Xcode seems to not want me to do it. They way I'm trying to do it is through interface builder (storyboard). I have no issue clicking and dragging to make IBOutlets and IBActions using the main View Controller but when I click and drag over to connect them in a custom class it does nothing. Am I only able to make these in the View Controller? I've attached a pic of me trying to drag over to connect my button in the custom class and you can see that nothing pops up. So basically, Are labels, buttons, text fields etc, for the View Controller class only? Thanks for any feedback.
Within interface builder, you will need to make sure your view controller is using your custom class by opening utilities view on the RHS of the IB, selecting the third icon along (please see picture below) and enter your custom class name in the space provided.
Your custom class will need to be a subclass of UIViewController though, like the picture below, not an NSObject for example.
I'm referring to this line within your .h file ...
#interface MyCustomClassViewController : UIViewController
Your custom class needs to match the UI object you are connecting it with. For example if you had UIView object, your custom class would need to be a subclass of UIView, a UINavigationViewController object, a subclass of UINavigationController etc etc.
I hope this helps.
Select your view controller in the stoyboard and go to the identity inspector, make sure the name there is your custom class name.

What superclass for a custom UI component?

I need to create a custom UI component that will satisfy the following:
it will contain a composition of UIViews, Labels, Button and a TableView.
it should be possible to instantiate it programatically - or - placing a UIView in nib editor and change the class in the inspector to my custom component class. (and it would the maintain/keep the main frame values from placed UIView)
I already started experimenting with it, I chose the UIView but it doesn't handle the ..cellForRow... cell method. On the other hand, if I use a UIViewController, then my class change in the inspector doesn't work and the app crashes.
Which one should I choose - UIView, UIviewController or NSObject?
I would go for UIViewController or UITableViewController, since you said you are having a tableView in it. If you do a UIViewController, you would probably have to include another UITableViewController inside it, using addChildViewController, as explained here
I believe the reason why your app is crashing is that you you changed your class superclass from UIView to UIViewController, but in the Interface Builder you still just have a UIView object. You need to change it to a UIViewController in the Interface Builder, and select your class as the File Owner.
If you intend this to be a stand-alone component, with all of the logic contained within the control, then I would base it on a UIViewController, like Apple does with the MFMailComposeViewController. If you want it to be strictly a view, with no built-in logic of its own, but instead delegates that logic, then use a UIView and delegate the table view methods to the controller that is using it.

Change TableView Size When It has AN XIB

My UITableViewController class uses an .xib. I would like to make the TableView only take up half the size of the screen, so that I could add more to it. Is there anyway to do this, or do I need to create it all in code, and not use .xib.
This thread covers a similar situation. In practice it would be easier to use a standard UIViewController and implement the UITableViewDataSource and Delegate methods manually.
you cannot resize the UITableViewController class,if you want to add something under table place it at it's footer.
You Can also declare UITableView in UIViewController through XIB through which you can resize it.
in .h File
IBOutlet UITableView *tView;
and connect it to file owner
Thanks

Resources