Setting the subclass of a UITableViewController - ios

I have created a project where I have a UITableViewController with static cells. I have created a UITableViewController subclass so that I can write the code for some of the controls I want to put in the static cells - however when I set the custom class of the UITableViewController to that of the subclass I've created, the table isn't displayed. Coudl anyone please help me with what to do that the table will be displayed after I've set the custom class of the UITableViewController?
Thanks

Assuming you are using storyboard and static cells: make sure the datasource methods in your controller do are not overriding the number of sections and rows in the table view. With static cells you can delete both numberOfRowsInSection: and numberOfSections.

Related

Populate data to UIcollectionview cell created with xib

I have create my custom collectionview cell with its own class. And I will register them programmatically on a UIviewcontroller class.
The problem I facing now is, I will do all the API call on the UIviewcontroller class but how to I populate them on all the cells I want, because each cell class also will have their own data source and delegate extension.
Note: There is a one cell class inside contain another collectionview.
Thanks.

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.

How to use a TableView inside a UIViewController?

I want to add a simple static TableView to my UIView. So i dragged it into my UIView. Added the TableViewDataSource and Delegate Protocols to my ViewController class. Created an outlet to my tableview and connected the datasource and delegate outlets to the viewcontroller.
But i still get an error message which says that Static table views are only valid when embedded in UITableViewCOntroller Instances ? Any Ideas how to solve this Problem ?
PS: I am using UIStoryboards for designing the UI
Use a containerView (drag one onto your UIView) which will link to a UITableViewController instead. You will use the prepareForSegue method to initialize the table view controller.
Oh, and you might want to accept answers that help you or no one will help you anymore.
If you want static cells, in your Storyboard, click on the tableview, then in the inspector, change the Content from 'Dynamic Prototypes' to Static Cells. You can also segue these cells to a new controller without having to set up data sources and delegates for the table.

IOS SplitView TableViewController query

I have one SplitViewController with default settings added into an xib file. Its Table View controller i defined as another class (in Identity Inspector) as a TableView Controller class I created.
Now I have put some code in its
...numberOfRowsInSection:(NSInteger) section
and ...cellForRowAtIndexPath:(NSIndexPath *) indexPath
It works fine with total values in its table according to numberOfRows I have defined and elements in cell according to what cells I create and return in the appropriate method.
My question is:
How is table coming into the SplitView because when I customize UITableView in the xib of my TableViewController, its changes do not appear in the SplitView's left section. (I guess that table View is non-customizable? )
Secondly How does iOS initialize that TableViewController class from XIB because I have to put some initialization code that when that TableView is created, do following things. I tried over-riding various init functions it does not call any of those. How can I initialize some data when that TableViewController is initialized?
Thanks.
The table view is customized in the XIB that contains the split view and not in an own XIB file
You can do 2 things: override initWithCoder: (remember to use the self=[super initWithCoder: pattern) or override - (void)awakeFromNib

UITableView in a View controller by a UIViewController and not a UITableView

I have a View with lots of things inside it including buttons, a scroll view and a tableView (ipad app). I am controller this view with a viewController subclass but I don't know how to manage my tableView. I don't know where put the methods :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
should I add them to my ViewController or should I create a new subclass of UITableViewController (and get them "for free") and set the dataSource and delegate of my tableView to that class when I create it programmatically?
I am storing the data I want to show in my appDelegate
.
You just have to set the UIViewController as the delegate and dataSource of your UITableView. That's it. You don't need to create a own subclass of UITableViewController for managing that tableView. So you can put all the subviews in the viewController's view.
Thank you so much, I got it. I was trying to create a tableView and then set it's datasource. In fact the easier way is to create a tableViewController and use it's .view property that is already linked to it and use the addSubview method to put it in the main viewController's view.
Cheers

Resources