I have encountered a very strange behavior, when I implemented navigationController.
I have a LogInViewController with an UITableView,where cells are populated like this:
- (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 and cellPassword are Cells which I created on .xib..
And when i add this LogInViewController as a rootViewController in my appDelegate it works fine!
I wanted to implement a navigationController, so I created RootViewController, with navController @property and in my appDelagate i called it like this
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;
And in my RootViewController on viewDidLoad I have this code:
[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!
I’m not sure if this has anything to do with your problem, but you shouldn’t be using this line in your viewDidLoad:
Your RootViewController is already embedded in a navigation controller, so you can just use self.navigationController to get a reference to it.
I’m also not sure about this code, it may be ok, but it’s not the way it’s usually done:
The usual way to do it is like this: