如何从故事板中的didSelectRowAtIndexPath打开视图控制器?

jca*_*cho 6 storyboard uitableview detailview

我有一个带tabbarcontroller的故事板.标签栏之一有一个tableview,我希望当用户从tableview中点击一行时打开一个详细视图.问题是当我打开详细视图标签栏和导航栏隐藏时...在故事板中我创建了一个新视图控制器的详细视图,然后我创建了一个新文件并将其引用到详细视图类.

didselectrowatindexpath中的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath {

detalleYouTube *dvController = [[detalleYouTube alloc] init];

[self.navigationController pushViewController:dvController animated:YES];

}
Run Code Online (Sandbox Code Playgroud)

先感谢您!

小智 6

这有点旧,但如果有人需要这样做,这是一个简单的方法:

您可以使用标签栏中的视图添加segue来detalleYouTube,将标识符添加到segue并执行以下操作:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath
{
[self performSegueWithIdentifier:@"segueIdentifier" sender:tableView];
}
Run Code Online (Sandbox Code Playgroud)


Sol*_*oth 5

另一种方法是不使用tableView:didSelectRowAtIndexPath而是使用prepareForSegue:sender

我这样做的方式是:

-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
    DetailViewController *viewController = [segue destinationViewController];
    CustomObject *custObject = [arrayOfObjects objectAtIndex:[self.tableView indexPathForSelectedRow].row];
    viewController.objectNeeded = custObject;
}
Run Code Online (Sandbox Code Playgroud)

此示例基于您的详细视图控制器已连接到表视图控制器的想法.


Her*_*rwr 4

我假设您将“详细信息”视图作为故事板的一部分(而不是在单独的 XIB 中),如果是这样,您将需要在“详细信息”TabBarItem 序列的开头放置一个单独的 NavigationController。

此页面有一个很好的教程,介绍了我认为您想要实现的目标: http://maybelost.com/2011/10/tutorial-storyboard-in-xcode-4-2-with-navigation-controller-and-tabbar-controller -第1部分/

另请查看以下链接以获得更深入的 Storyboard 教程:

http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2