开发者

Cocoa-Touch: UITableView not resizing

I have an app, which has a top navigation bar and a bottom tab bar.

One of the tabs displays a table's XIB file with my custom controller.

This UITableView is created by a MyTableViewController class.

I have a problem with the table's size. The table's frame size is bad (it's the fullscreen iphone size, without the status/tab/navigation bar sizes taken into consideration) however it's placing is good (it starts under the navigation bar).开发者_开发知识库

In the table's XIB (which is a separate XIB file that only holds the table), I've tried setting and removing the top/bottom (nav/tab) bars to change the table size.

It didn't help.

Then I tried customizing it from the controller:

- (void)viewDidLoad {
    self.view.frame = CGRectMake(0, 20, 320, 270); // a lot shorter than I need it, but just to prove the point
    [super viewDidLoad];
}

I've set a breakpoint there, and viewDidLoad is in fact getting called, but the table is of the same size.

What am I doing wrong?


Make sure you have your "Springs & Struts" (Tools Menu > Size Inspector) in Interface Builder set so that it's a properly expanding/contracting view. Most likely, this will mean 4 solid red lines around the outside of the box, and two inside (no dotted lines visible).


What if you call [super viewDidLoad] first before setting the frame. Since you are loading your view from XIB, it's possible that [super viewDidLoad] will override your self.view.frame = ...

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.frame = CGRectMake(0, 20, 320, 270); // a lot shorter than I need it, but just to prove the point
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜