didselectrowatindexpath的问题

时间:2010-04-13 13:24:46

标签: iphone objective-c cocoa-touch uinavigationcontroller uitabbarcontroller

我刚刚将我正在制作的应用程序从导航控制器应用程序转换为标签栏应用程序。

除了这一件事之外,一切都很好,我的第一个标签带来了一个表视图,我想要发生的是当用户选择一个单元格时我希望它能够推送一个不同的视图控制器(就像它一样)当它是导航应用程序时做了)

但这似乎不再起作用,我在做些傻事

- (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];
}

1 个答案:

答案 0 :(得分:3)

问题出在self.navigationController。由于它不再是导航控制器的一部分,navigationControllernil。如果要将新视图推送到层次结构,可以通过创建将该视图作为其根视图控制器的导航控制器,然后将导航控制器的视图添加到选项卡栏来实现。