如何使用以编程方式加载的故事板执行转场?
我需要从我的故事板执行一个segue。在这种情况下调用的方法是 -[UIViewController PerformSegueWithIdentifier:sender:]
。此方法依赖于 UIViewController
的 storyboard
属性来查找 Storyboard(以及 Segue)。
但是,当未从情节提要创建 UIViewController
时,不会设置 storyboard
属性。由于它是只读的,我无法在加载故事板的位置以编程方式设置它。
所以问题是:如何从以编程方式加载的情节提要中执行转场?
如果不可能,可能是因为我的架构不正确。以下是用例:
该应用程序是一个传统的选项卡应用程序,其中 8 个选项卡中的每一个都有自己的 NIB 文件。 8 个选项卡中的许多选项卡都相当复杂,并且可以从情节提要中受益匪浅,尤其是原型表格单元格和静态表格。所以我想改进应用程序以使用故事板。
然而,一个巨大的故事板似乎不是一个好主意:它会阻止对应用程序的增量更改,它会很笨重,它会让团队成员很难独立地处理他们的选项卡。
正确的模块化水平似乎让 UITabBarController
拥有自己特定的故事板。这使得每个选项卡都可以按照自己的节奏发展,并且使每个开发人员可以更轻松地在他们的选项卡上工作,而几乎没有源代码控制冲突。
到目前为止,我的方法是使用主 nib 文件来包含 UITabBarController 及其每个主要子视图控制器。子视图控制器从其 viewDidLoad 方法加载故事板。从那里开始,他们就无法执行他们的转场了。
另一种方法是从故事板创建子视图控制器,但是如何将它们连接到 UITabBarController?我在哪里以编程方式加载故事板?
感谢您的任何建议。
I need to perform a segue from my storyboard. The method to call in that case is -[UIViewController performSegueWithIdentifier:sender:]
. This method relies on the storyboard
property of UIViewController
to find the storyboard (and therefore the segue).
However, the storyboard
property is not set when the UIViewController
was not created from the storyboard. And since it's read-only, I can't set it programmatically where I load my storyboard.
So the question is: how to perform a segue from a storyboard that has been loaded programmatically?
If it's not possible, it's perhaps because my architecture is incorrect. Here is the use case:
The app is a legacy tabbar application where each of the 8 tabs has its own NIB file. Many of the 8 tabs are rather complex, and can benefit a lot from storyboards, especially prototype table cells and static tables. So I want to evolve the app to use storyboards.
However, one humongous storyboard doesn't seem a good idea: it would prevent incremental changes to the app, it would be unwieldy, it would make it difficult for the team members to work on their tab independently.
The right level of modularity seems to let the UITabBarController
have its own specific storyboard. This makes it possible for each tab to evolve at its own pace and makes it easier for each developers to work on their tab with few source control conflicts.
My approach so far is the main nib file to contain the UITabBarController
and each of its main daughter view controllers. The daughter view controllers load their storyboard from their viewDidLoad
method. And from there, they can't perform their segue.
The alternative would be for the daughter view controllers to be created from their storyboards, but then how can I hook them up to the UITabBarController
? And where do I programmatically load the storyboards?
Thanks for any suggestion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 segue 上进行引用并将指针值保存在单例类中。然后使用保存在单例类中的指针引用,在您喜欢的任何地方访问segue并加载它。这是一个示例代码,其中我从单个故事板类加载 Segue 视图,但每个视图都有单独的视图控制器 .h 和 .m 文件,它们具有适当的连接。 (我使用了正式协议,因此该行 shareVC.delegate = self; 在那里。
希望这有帮助:)
make a reference on the segue and save the pointer value in a singleton class. Then using the pointer reference saved in the singleton class, access the segue wherever you like and load it. Here is a sample code in which i am loading a segue view from a single storyboard class but each view has separate view controllers .h and .m files that have appropiate connections. (i used formal protocol, hence the line shareVC.delegate = self; is there .
Hope this helps:)