开发者

UINavigationController and UITableView frame issue

self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

How do I get the proper size from the view, when I have a UINavigationController and a UITabBarController?

In order to get around it I have to do:

CGRect frame = self.view.frame;
frame.origin.y -= [UIApplication sharedApplication].statusBarFrame.size.height;
tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];

I always have to manually set the height of my views/tableviews in order to fit inside the UINavigationController and it's really annoying

This seems kinda strange, why would it not subtract the statusbar height auotmatically? It's the default style, not transparent statusbar.

Thanks

UPDATE: If I alloc the tableView AFTER the init method, just开发者_如何学Python setting the frame to self.view.frame works fine. Wuzzup wit dat?


Setting the frame of the UINavigationController before the init method wouldn't work because the UINavigationController hasn't been loaded and displayed yet. The frame is only set after the controller and its view has been loaded.

You should be setting up your table (and all similar initializations) in the viewDidLoad method of the UINavigationController. If you do that you won't see any problems of this sort.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜