Elton's Blog

Tag: UITableVIewController

loadView时候的注意事项

by on 十一.17, 2009, under iPhone

loadView是使用代码生成视图的时候,当视图第一次载入的时候调用的方法。

今天写一个Navigation Controller,给它加一个继承了TableViewController的View作为Navigation Controller的Root View

1
2
3
4
5
UITableViewController *tableViewController = [[TableViewController alloc] init];
 
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: tableViewController];
nav.navigationBar.barStyle = UIBarStyleBlack;
[self.view addSubview:nav.view];

一切都很顺利成章,但是运行的时候,除了显示一个NavigationBar以外,表格并没有显示出来。 反复查找原因都为果。 后来仔细对比之前的代码,原来是tablebView中的loadView方法少写了下面这行代码:

1
[super loadView];

后来查了文档,说的很清楚,自己的类里面的loadView一定要第一行加上[super loadView]这句话。 看来以后还是要多注意细节。

1 Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit my friends!

A few highly recommended friends...