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 = [app开发者_如何学CDelegate.stories objectAtIndex:indexPath.row];
[self.navigationController pushViewController:storyDetailViewController animated:NO];
NSLog(@"view controller pushed");
[StoryDetailViewController release];
}
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.
精彩评论