我正在编写一个复杂的 Storyboard 应用程序,当涉及到跨 View Controller 和不同应用程序路径的代码重用时,我遇到了一些问题。
我可以继续到一个没有直接连接到当前 View Controller 的 ViewController 吗?
如何有条件地从一个按钮转出到多个 ViewController?连接两者不起作用。
我可以从应用程序中的任意位置输入 ViewController 序列吗?
只是提出了几个问题。有人有任何想法或好的例子吗?
最佳答案
Can I segue to a ViewController that is not directly connected to the current one?
不带segue。但是您可以从 Storyboard中模态地推送或呈现 viewController,就像您对 .xib 文件所做的那样。
// if self was created from code or from a .xib:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil];
// if self was instantiated from within a storyboard:
UIStoryboard *storyBoard = self.storyboard;
MyFancyViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"MyFancyViewControllerIdentifier"];
[self presentModalViewController:viewController animated:YES];
但是你必须先设置标识符。在 Storyboard中选择 viewController 并在属性检查器中执行此操作。
一旦 MyFancyViewController 可见,您就可以使用它的所有 segues。在代码和 Storyboard segues 之间切换可能感觉很奇怪,但这并没有错。它使整个 Storyboard真正可用。
How do I segue out from a button to several ViewControllers conditionally? Connecting both does not work.
添加两个或多个从 viewController(不是从按钮或任何其他 View 开始。例如,在状态栏开始控制拖动)到目标 viewController 的转场。为它们设置标识符并使用如下代码:
if (someState) {
[self performSegueWithIdentifier:@"MyFirstSegueIdentifier" sender:somethingOrNil];
}
else {
[self performSegueWithIdentifier:@"MySecondSegueIdentifier" sender:somethingOrNil];
}
Can I enter the ViewController sequence from an arbitrary position in the application?
是的,如果您使用“老派” View Controller 管理。与第一部分类似。实例化您的 viewController 并用代码呈现它。
关于iphone - 希望在 iPhone Storyboard应用程序中最大限度地重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9924043/