allpnay allpnay - 1 month ago 7
iOS Question

iOS table navcontroller not working

I have a table:

- (void)viewWillAppear:(BOOL)animated
{

self.searchBar.delegate=self;
self.searchResultTable.delegate=self;
self.searchResultTable.dataSource=self;
[self.searchResultTable setHidden:YES];

}


In my cells I insert text and when I click on cell I need go to another table but this not work:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

TableViewController *tvc=[[TableViewController alloc]initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:tvc animated:YES];
}

Answer

Assuming you are doing something like this to present this controller:

SearchViewController *searchViewController = [SearchViewController alloc] init];
[self presentModalViewController:searchViewController animated:YES];

then your view controller doesn't have a navigation controller

You need to change it to

SearchViewController *searchViewController = [SearchViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:searchViewController];
[self presentModalViewController:navController animated:YES];

then [self.navigationController pushViewController:tvc animated:YES]; will work