I've inserted a UITableViewController and it's corresponding UITableView into a simple IB document. The goal is to include the UITableView inside of a parent UIWindow (or UIView) with other "stuff" (anything really) adorning the table. Here's what that might look like in Interface Builder.
I've tried this numerous times and always get to the same place.
When running the app in the iPhone emulator or on a device the table displays correctly, but crashes the first time you try and interact with it. A scroll, a tap, anything crashes the app. This seems to be a delegate problem, like the UITableView doesn't know how to communicate back to the UITableViewController, but I have no idea how to correct the problem.
So far I have been able to get by by customizing the tableHeaderView to get layouts that suffice, but I'd really prefer to have the other technique work.
The way I achieve adding spacing between cells is to make numberOfSections = "Your array count" and make each section contains only one row. And then define headerView and its height. This works great.
To be precise, table views and collection views are also scroll views. If you look at the documentation of the UITableView class, you will see that it descends from UIScrollView.
You're on the right track! Here's what you need to do:
Create a standard UIViewController subclass with its accompanying view xib.
Add a UITableView in the XIB.
Wire everything up. The view controller will be the delegate and the datasource for your table, so you must implement both protocols.
In your implementation file, add all of the necessary datasource and delegate methods needed for the tableview:
(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
Your header file may look something like this:
MyViewController.h
@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> { IBOutlet UITableView *myTableView; //This outlet is only necessary if you need to send messages to the table view (such as reloadData) } @end
That should do it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With