如何在多个UIViewController之间共享一个情节提要场景 [英] How to share one storyboard scene between multiple UIViewControllers

查看:92
本文介绍了如何在多个UIViewController之间共享一个情节提要场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

了解到我本来是偏离轨道的,但是我离解决该问题的距离越来越近了,我将完全重新制定这个问题.参考此图片...

I'm completely re-formulating this question having learned that I was originally off track but that having me no closer to solving the problem. With reference to this image...

我要创建或操纵代码中的segue(以黄色突出显示),以使Master视图是MFMasterViewController(以红色突出显示)的多个子类中的任何一个.

I am wanting to either create or manipulate the segue (highlighted in yellow) in code such that the Master view is any one of a number of subclasses of MFMasterViewController (highlighted in red).

使用笔尖执行此操作时,我可以创建一个笔尖SharedNib.xib&将类设置为MFMasterViewController,然后创建我的子类,例如MFMasterViewControllerSubclassAMFMasterViewControllerSubclassB等.然后实例化我想要使用的任何子类...

When doing this using Nibs I could create a Nib, SharedNib.xib & set the class as MFMasterViewController, then create my subclasses, say MFMasterViewControllerSubclassA, MFMasterViewControllerSubclassB etc. & then instantiate whichever subclass I wanted using...

MFMasterViewControllerSubclassA *controller = [[MFMasterViewControllerSubclassA alloc] initWithNibName:@"SharedNib" bundle:nil];

或...

MFMasterViewControllerSubclassB *controller = [[MFMasterViewControllerSubclassB alloc] initWithNibName:@"SharedNib" bundle:nil];

关于如何使用情节提要正确解决此问题的任何线索?

Any clues as to how I can get this right using storyboards?

在我的情况下,要这样做的原因是我所有的子类都具有相同的表视图&数据,但排序方式不同&在单元格的详细文本中写入的内容有所不同.我怀疑这是一种不常见的模式.

In my case the reason for wanting to do this is that all my subclasses are the same tableview & data but sorted differently & having some difference in what's written to the detail text of the cels. I suspect that it is a not uncommon pattern.

干杯TIA, 佩德罗:)

Cheers & TIA, Pedro :)

推荐答案

这不是直接的答案,但这是我根据您对原因的解释来完成您想要的事情.

It's not a direct answer but this is how I would accomplish what you want based on your explanation of the reason.

基本上,您需要将UITableViewDataSource(可能还有委托)与MFMasterViewController分开,因此当执行segue时,可以在视图控制器中设置正确的dataSource和委托.

Basically you need to separate the UITableViewDataSource (and maybe the delegate too) from the MFMasterViewController so when the segue is executed you can set the correct dataSource and delegate in the view controller.

因此,在导航控制器中,您需要实现prepareForSegue:sender:方法.在这里,您可以在执行segue之前自定义它:

So in the Navigation Controller you need to implement the prepareForSegue:sender: method. This is where you can customize the segue before it is executed:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // you can set the segue identifier using Interface Builder 
    // also it is a good thing to make sure which segue you're using
    if (([segue identifier] isEqualToString:@"TheId"]) {
       id<UITableViewDataSource> dataSource = [[TableViewDataSourceImplementationA alloc] init];
       [[[segue destinationViewController] tableView] setDataSource:dataSource];
    }
}

这样,您无需创建视图控制器的子类即可获得所需的自定义.

This way you can get the customization you want without the need to create subclasses of your view controller.

如果您有权访问WWDC视频,请查看会话#407在应用程序中采用情节提要.

And if you have access to WWDC videos, check the session #407 Adopting Storyboards in Your App.

这篇关于如何在多个UIViewController之间共享一个情节提要场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆