简体   繁体   English

如何使用情节提要选择到UIViewController的几种子类型之一?

[英]How to segue to one of several subtypes of UIViewController with a storyboard?

I have a table whose detail-disclosure buttons bring up a MyDetailViewController and in performSegueWithIdentifier:sender: I have been setting a few variables. 我有一个表,其详细信息显示按钮调出了MyDetailViewController并且在performSegueWithIdentifier:sender:我一直在设置一些变量。 But it turns out that I need something more complex: I need subtypes of MyDetailViewController ( MyFooController : MyDetailViewController , MyBarController : MyDetailViewController , etc.) based on what row is selected. 但是事实证明,我需要更复杂的东西:根据选择的行,我需要MyDetailViewController 子类型MyFooController : MyDetailViewControllerMyBarController : MyDetailViewController等)。

My first thought was to assign to the destinationViewController in the UIStoryboardSegue in performSegueWithIdentifer:sender: but that is a read-only variable. 我的第一个想法是在performSegueWithIdentifer:sender:分配给UIStoryboardSegue中的destinationViewController ,但这是一个只读变量。

Is there an easy way to do this with Storyboards? 有没有一个简单的方法可以通过情节提要来做到这一点? Should I create a custom Segue? 我应该创建自定义Segue吗? Or should I just do it programmatically? 还是应该以编程方式进行?

You can either use multiple segues, one for each of your subtypes of controllers, there is no actual limit to how many you can use from one viewController, or you can, depending on the cell that was selected, instantiate a view controller, and push it on the stack manually, something in the lines of: 您可以使用多种选择,一种用于您的控制器的每个子类型,对一个viewController可以使用的数量没有实际限制,或者可以根据所选的单元实例化一个视图控制器,然后按入手动将其放在堆栈中,如下所示:

MyBarController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"myBarController"]; // You set the identifiers in the storyboard itself
[self.navigationController pushViewController:vc animated:YES];

You can't connect multiple segues to a detail-disclosure button, but you can connect as many segues as you want from the controller. 您不能将多个序列连接到详细信息披露按钮,但是可以从控制器连接任意数量的序列。 Implement tableView:accessoryButtonTappedForRowWithIndexPath:, and that method will be called when a user taps the button. 实现tableView:accessoryButtonTappedForRowWithIndexPath :,当用户点击按钮时将调用该方法。 You can use the indexPath argument to decide which segue to execute, and then invoke the segue using performSegueWithIdentifier. 您可以使用indexPath参数来确定要执行哪个segue,然后使用performSegueWithIdentifier调用该segue。

As a third alternative, you could create different prototype cells in the storyboard, give each a different reuseIdentifier , and create the different segues from each prototype cell. 作为第三种选择,你可以在故事板制作不同的原型细胞,给每一个不同的reuseIdentifier ,并创建从每个原型细胞的不同塞格斯。 Then in your cellForRowAtIndexPath: method, select the correct reuseIdentifier when dequeue-ing cells, according to the row. 然后,在cellForRowAtIndexPath:方法中,根据该行,在使单元出队时选择正确的reuseIdentifier

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式从UINavigationController(storyboard)到UIViewController - How to segue from UINavigationController (storyboard) to UIViewController programmatically 如何防止Storyboard Segue重置UIPopoverController中的UIViewController - How to prevent Storyboard Segue from resetting UIViewController inside UIPopoverController 如何使用情节提要segue将UIViewController连接到UIView,而无需任何代码? - How to connect UIViewController to UIView using storyboard segue, without any code? 如何在故事板上创建一个Segue,从编程注册的UICollectionViewCell到新的UIViewController? - How to create a Segue on the Storyboard, from a programmatically registered UICollectionViewCell to a new UIViewController? 重用情节提要中涉及的细节UIViewController - Reusing a detail UIViewController involved in a storyboard segue 如何在一个 UIViewController 中控制多个相同的 UIView - How to control several same UIViews in one UIViewController 如何替换情节提要剧集 - How to replace storyboard segue 如何阻止故事板segue - How to block storyboard segue 如何在不使用 Storyboard segue 的情况下将项目从单独的 UIViewController 添加到 UICollectionViewController? - How to add item to a UICollectionViewController from a separate UIViewController without using Storyboard segue? 如何以编程方式从一个UIViewController切换到另一个,而无需模态或Push? - How to programmatic segue from one UIViewController to another without Modal or Push?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM