处理TableViewController,可能转到两个控制器之一,一个是UIWebViewController

Noob在iOS开发。 这只是一个可行性问题。 我想看看是否有可能有一个TableViewController,并根据推入到单元格中的数据types,让它在两个不同的控制器之间做一个pushViewController。

比如说,我们有位置和人员可以返回作为search结果,我们要么做一个PushViewController与ProfileController或LocationController? 如果其中一个控制器是一个UIWebView的话,它会影响吗?

谢谢

编辑1我想我正在寻找一种方式来说,如果一个TableView单元格响应类似于这个问题的特定消息在Objective-C中,给定一个id,我怎么能告诉它指向什么types的对象? 并确定推送哪个UIViewController。

如果你想“推”另一个审查控制器,你的表视图控制器应该embedded在一个UINavigationController。 然后,select一行时,有两种方法可以处理新的视图控制器:

如果没有故事板(iOS 5.0),你最好的机会就是在表视图的委托(通常是表视图控制器)上调用-tableView:didSelectRowAtIndexPath: 从那里,你可以根据传入的indexPath来select去哪里,创build一个你想要去的视图控制器的实例,并把它推到导航控制器上。 例如:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UIViewController *nextVC; if (indexPath.section == 0) { nextVC = [[ProfileController alloc] init]; // configure nextVC as needed } else { nextVC = [[LocationController alloc] init]; // configure nextVC as needed } [self.navigationController pushViewController:nextVC animated:YES]; } 

使用Storyboard(iOS 5.0+),正常的做法是将IB中的segue从表格单元格拖到下一个视图控制器,然后根据-prepareForSegue:sender:的选项实现您的逻辑以configuration目标视图控制器-prepareForSegue:sender: …但是不能从同一个表格单元中拖动多个segues。 相反,从视图控制器本身拖动segues,并给他们的标识符。 在-tableView:didSelectRowAtIndexPath:select-tableView:didSelectRowAtIndexPath:如前所述,但是调用performSegueWithIdentifier:而不是自己创build目标视图控制器。 例如:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { [self peformSegueWithIdentifier:@"showProfile"]; } else { [self peformSegueWithIdentifier:@"showLocation"]; } } 

如果您需要基于哪个表格行被点击来configuration目标视图控制器,请在-prepareForSegue:sender:

没有UIWebViewController …但不pipe你的一个视图控制器是否pipe理了一个UIWebView,这都是一样的。