ios - 在多个子类之间共享 Storyboard View Controller

标签 ios cocoa-touch uistoryboard uistoryboardsegue

我和佩德罗有同样的问题here但对答案不满意,因为已经有赏金和奖励,我创建了这个问题,我会尽快增加赏金。

我想在代码中创建或操作一个 segue(以黄色突出显示),以便主视图是 MFMasterViewController(以红色突出显示)的多个子类中的任何一个。

storyboard illustration

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];

or...

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

etc.

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

我不能对 Pedro 的问题使用提供的答案,我的子类化超出了数据源和委托(delegate)。

最佳答案

您可以将未连接的 View Controller 添加到您的 Storyboard并为它们提供标识符。然后在代码中你可以在你的导航 Controller 子类中做这样的事情:

MFMasterViewControllerSubclassA *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"SubclassA"];
self.viewControllers = @[controller];

这会将导航 Controller 的 Root View Controller 更改为 Controller 。如果你想为变化设置动画,那么你可以使用 setViewControllers:animated: 而不是第二行。

关于ios - 在多个子类之间共享 Storyboard View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13602891/

相关文章:

android - 伪元素:after disapears on chrome mobile

iphone - 可以取消UIPickerView动量动画吗?

iphone - 除了为 iOS 6.1 设置 UIApplication idleTimerDisabled 以简单地表示用户已经主动做了某事之外,还有其他选择吗?

ios - 如何在 iOS 5 中使用 Embed Segue?

ios - 针对 iPad 和 iPhone 进行测试时颜色不同

iphone - Delphi XE2 中标准外观的 iOS 控件\样式在哪里?

ios - Facebook 分享对话框 : Permission Error - OAuth "Facebook Platform" "insufficient_scope (#200) Permissions error"

ios - 使用 uicollectionview Swift 更新单个 View

ios - 重用 LaunchScreen.storyboard xib

iphone - iOS 上的矢量 PDF 图形元素