In viewDidLoad I add a tableview to navigationController like this :
[self.view addSubview:navigationController.view];
[self.navigationController.view addSubview:tableViewRecherchePartenaire];
When a row from tableview is selected I want this tableview to disappear and I tried something like this :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){
NSLog(@"RecherchePartenaireTypePartenaireViewController...");
[self.navigationController.view removeFromSuperview];
recherchePartenaireTypePartenaireViewController=[[RecherchePartenaireTypePartenaireViewController alloc] init];
recherchePartenaireTypePartenaireViewController.recherchePartenaireViewController=self.view;
[self.navigationController pushViewController:recherchePartenaireTypePartenaireViewController animated:YES];
[recherchePartenaireTypePartenaireViewController release];
}
}
but the tableview disappear but the next view is not appear. How can I use the table view with the navigationController ? Please help…I spent a lot of time with this and I can see the mistake..Thanks in advance..
First of all, you must not add subview to
UINavigationController‘s view. Put yourUITableViewin a subclass ofUIViewControllerand make it therootViewControllerof your navigationController. You can do it in your main xib file or programmatically :After you can almost keep your function :
But this function will be in myTableViewController.
In your code, you were removing your navigationController’s view from the view hierarchy. So it’s normal that nothing came up when you were pushing something, because
UINavigationControllerhandle push by pushing the next controller’s view on it’s own view.Here is a nice Apple’s sample that could help you 🙂
http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007419