0
votes

I'm trying to create a small app in iOS. After the Login Page, I have a TabBarController and the first tab in it is a TableViewController. In didSelectRowAtIndexPath I'm trying to push one view controller for every selected row. The same view controller but self.navigationController is (null) when I print it using an NSLog and I'm not able to push the ViewController. HELP!!

Here's the sample Code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here, for example:
    // Create the next view controller.
    PlayerDetailsViewController *detailViewController = [[PlayerDetailsViewController alloc] initWithNibName:@"PlayerDetailsViewController" bundle:nil];
    detailViewController.myImg.image=[UIImage imageNamed:[self.arrNames objectAtIndex:indexPath.row]];
    detailViewController.name.text=[self.names objectAtIndex:indexPath.row];
    detailViewController.year.text=[self.draft objectAtIndex:indexPath.row];
    detailViewController.height.text=[self.height objectAtIndex:indexPath.row];
    detailViewController.weight.text=[self.weight objectAtIndex:indexPath.row];
    detailViewController.pro.text=[self.pro objectAtIndex:indexPath.row];
    detailViewController.ppg.text=[self.ppg objectAtIndex:indexPath.row];
    detailViewController.apg.text=[self.apg objectAtIndex:indexPath.row];
    detailViewController.rpg.text=[self.rpg objectAtIndex:indexPath.row];
    NSLog(@"%@",self.navigationController);


    [self.navigationController pushViewController:detailViewController animated:YES];

}

UPDATE: I got the navigationController to work but now, the data in the pushed view(PlayerDetails) in blank!!

2
There's no UINavigationController on responder hierarchy. Set you UITabBarController or TableViewController as a rootViewController of UINavigationController.Ryan
May I please know how I can come around to do that?sam24

2 Answers

0
votes

It's just wrong that you haven't nested your firstViewController inside UINavigationController.

So I guess your code will be seems like this when creating UITabViewController.

[tabVC setViewControllers:[vc1,vc2,nil]];//tabVC = UITabViewController

And it need to be changed something like below;

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc1];
[tabVC setViewControllers:[nav,vc2,nil]];
0
votes

Assume that the instance of UITabBarController is tabVC and the instance of UITableViewController is tableVC.

UINavigationController *nav = [[UINavigationController alloc initWithRootViewController:tabVC];

or

UINavigationController *nav = [[UINavigationController alloc initWithRootViewController:tableVC];
[tabVC setViewControllers:@[nav]];

Both will fix your problem.