Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView uses all available space in Interface Builder

I'm having trouble creating a UIView (in Interface Builder) that contains a UITableView with some other object, such as a UIButton or UILabel. The UITableView always takes up the maximum amount of space in the UIView, regardless of the size of the UITableView object itself. The File Owner is a standard UITableViewController.

like image 316
James Sun Avatar asked Oct 23 '09 21:10

James Sun


1 Answers

Here's how to do this easily:

1) Create a table view controller with xib.

2) Change the inherited type in the .h file from UITableViewController, to UIViewController.

3) Add the protocols UITableViewDataSource, UITableViewDelegate to the .h file.

4) Open the xib, add in a view.

5) drag the table view in the xib under the view, resize as desired.

6) Wire the "view" property of the File's Owner to the View instead of the UITableView. The datasource and delegate properties of the table view should still be wired to File's Owner.

7) (optional) if you want to be able to reload or otherwise access the table outside of table view controller delegate methods that pass in a table view, make a UITableView * IBOutlet named "myTable" or the like, and wire the table in IB to that.


An alternate approach is to make a new UIViewController with xib, add a table to the xib, wire datasource/delegate to the file's owner, and make a new UITableViewController class which you use to copy the methods from into your view controller, then delete.

like image 108
Kendall Helmstetter Gelner Avatar answered Oct 21 '22 04:10

Kendall Helmstetter Gelner