didselectrowatindexpath 的问题

发布于 2024-08-28 12:14:41 字数 1139 浏览 7 评论 0原文

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

除了这一件事之外,一切都工作正常,我的第一个选项卡引入了一个表格视图,我想要发生的是,当用户选择一个单元格时,我希望它推送到不同的视图控制器上(就像它时所做的那样)是一个导航应用程序)

但这似乎不再起作用,我是在做一些愚蠢的事情吗

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2024-09-04 12:14:41

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文