didselectrowatindexpath 的问题
我刚刚将我正在制作的应用程序从导航控制器应用程序转换为选项卡栏应用程序。
除了这一件事之外,一切都工作正常,我的第一个选项卡引入了一个表格视图,我想要发生的是,当用户选择一个单元格时,我希望它推送到不同的视图控制器上(就像它时所做的那样)是一个导航应用程序)
但这似乎不再起作用,我是在做一些愚蠢的事情吗
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在 self.navigationController 中。由于它不再是导航控制器的一部分,因此
navigationController
为nil
。如果要将新视图推送到层次结构中,可以通过创建一个将该视图作为其根视图控制器的导航控制器,然后将导航控制器的视图添加到选项卡栏来实现。The problem is in
self.navigationController
. Since it's no longer part of a navigation controller,navigationController
isnil
. 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.