当我实现navigationController时,我遇到了一个非常奇怪的行为。我有一个带有 UITableView 的 LogInViewController,其中的单元格填充如下:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return cellUsername;
}
if (indexPath.row == 1){
return cellPassword;
}
else{
return nil;
}
}
cellUsername 和 cellPassword 是我在 .xib 上创建的单元格。当我将此 LogInViewController 作为 rootViewController 添加到我的 appDelegate 中时,它工作正常!我想实现一个navigationController,所以我用navController @property创建了RootViewController,在我的appDelagate中我这样称呼它
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
RootViewController *rootView = [[RootViewController alloc]init];
rootView.navController = [[UINavigationController alloc] initWithRootViewController:rootView];
self.window.rootViewController = rootView.navController;
[self.window makeKeyAndVisible];
return YES;
在 viewDidLoad 上的 RootViewController 中,我有以下代码:
[super viewDidLoad];
self.navController = [[UINavigationController alloc]init];
LogInViewController *loginView = [[LogInViewController alloc]init];
[[self navigationController] pushViewController:loginView animated:YES];
It opens my LogInViewController,but only the first cell,cellUsername is added to my UiTableView, what is wrong? Am still a beginner,so I might be missing something stupid probably.. but it works wihout navigationController,so am pretty confused.. Thank you!