iphone - 希望在 iPhone Storyboard应用程序中最大限度地重用

标签 iphone ios xcode storyboard

我正在编写一个复杂的 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/

相关文章:

iphone - 如何默认选择 UITableViewCell?

ios - swift5 中更新和删除钥匙串(keychain)时出现问题

android - react native : Null is not an object - Push notification (OneSignal)

ios - CLLocationDistance 不起作用 - 快速

iphone - 构建警告 : Disabling subview autoresizing is not supported on iPhone OS versions prior to 3. 0

iphone - 没有 GameKit 的 iOS 蓝牙

iphone - UIViewController背景图片

iphone - 在另一个类中使用一个类中的字符串变量

ios - 如何在 iOS 上获取联系人并存储在数组中?

iphone - 无法在 xcode 中生成 iOS App 存档