views:

45

answers:

1

hi there,

i have just converted an app i was making from a navigation controller app into a tab bar app.

an everything works fine apart from this one thing, the first of my tabs brings in a table view,and what i want to happen is when a user selects a cell i want it to push on a different view controller(like it did when it was a navigation app)

but this no longer seems to work, am i doing something silly

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];


    StoryDetailViewController *storyDetailViewController = [[StoryDetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];



    WorldCupAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;

    Story *aStory = [appDelegate.stories objectAtIndex:indexPath.row];
    NSURL *url = [NSURL URLWithString:aStory.picture];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *img = [[UIImage alloc] initWithData:data];
    storyDetailViewController.downloadedImage = img;


    storyDetailViewController.story = [appDelegate.stories objectAtIndex:indexPath.row];


    [self.navigationController pushViewController:storyDetailViewController animated:NO];

    NSLog(@"view controller pushed");

    [StoryDetailViewController release];
}
+2  A: 

The problem is in self.navigationController. Since it's no longer part of a navigation controller, navigationController is nil. If you want to push new views onto the hierarchy, you can do so by creating a navigation controller with that view as its root view controller, and then adding the navigation controller's view to the tab bar instead.

Jeff Kelley
brilliant , thanks
richard Stephenson