开发者

UITableView uses all available space in Interface Builder

I'm having trouble creating a UIView (in Interface开发者_JAVA技巧 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.


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.


Unfortunately, creating a UITableView in Interface Builder (IB) is was very problematic for me. I ran into the same problems as you as a beginning developer and, after much frustration, just ended up abandoning IB for UITableViews.

The best solution for me was to just implement the UITableViewController (and the UINavigationController that you use as a header) programmatically. Once you figure out the whole Model-View-Controller paradigm, it is actually fairly straightforward.

Some good resources for dealing with them programmatically can be found in Apple's documentation with these names:

"Table View Programming Guide for iPhone OS"
"View Controller Programming Guide for iPhone OS"


Cocoa with love has an article about Recreating UITableViewController to increase code reuse. This is useful if you can't use a UITableViewController, but want to make sure that your UIViewController will behave the same way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜