[英]Segue to different controllers from one cell (a detail view and a avcontroller)
[英]How do I segue to different detail view controllers?
在拆分视图控制器应用程序中,如何在主视图控制器中选择表行后选择不同的详细视图控制器?
为了清楚起见,当我在主视图控制器中选择一行时,我需要替换详细视图控制器。 如何连接视图控制器? 从拆分视图控制器? 或从详细视图导航控制器?
在您的tableView:didSelectRowAtIndexPath:
方法中,执行以下操作:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"YourSegueIdentifier" sender:self];
}
如果需要根据选定的行执行不同的排序,请执行以下操作:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *segueIdentifier = nil;
switch(indexPath.row) {
case 0:
segueIdentifier = @"YourSegueIdentifier";
break;
case 1:
segueIdentifier = @"ADifferentSegueIdentifier";
break;
.
.
.
}
if (segueIdentifier != nil) {
[self performSegueWithIdentifier:segueIdentifier sender:self];
}
}
在主表视图的委托中实现tableView:didSelectRowAtIndexPath:
根据indexPath
参数的值,使用您选择的segue标识符调用[detailViewController performSegueWithIdentifier:sender:]
。
// Get detail navigation controller
UINavigationController *detailNavigationController = [splitViewController.viewControllers objectAtIndex:1];
// Push the detail view controller
[detailNavigationController pushViewController:anyDetailViewController animated:NO];
// You also might need to set the splitview controller's delegate to this view controller
splitViewController.delegate = anyDetailViewController;
使用此代码:
UINavigationController *detailNavigationController =[[[self splitViewController] viewControllers] objectAtIndex:1];
[detailNavigationController pushViewController:"your_view_controller" animated:YES];
在您的搜索中,将样式设置为“推送”,将目的地设置为“详细信息”。 当前将把目标视图控制器推到您的主视图上,而细节将把它推到“细节”视图中。 就这么简单。 然后将其连接起来,就像连接其他所有东西一样。
但是请注意 ,如果您没有实现等待上一个序列的方法,则在将新Controller推入详细视图之前将其推入另一个视图之前,可能会出现“不平衡呼叫”错误。 双击表中的单元格即可完成操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.