gpt4 book ai didi

ios - 从 ViewController 标识符中获取 StoryBoard

转载 作者:行者123 更新时间:2023-12-01 19:11:10 24 4
gpt4 key购买 nike

我正在使用 3 个 Storyboard,并且在一段代码中,我得到了 ViewController 的标识符,但无法调用 instantiateViewControllerWithIdentifier,因为我不知道哪个 Storyboard属于它。

问题是:是否可以使用 ViewController 标识符获取 StoryBoard 实例/标识符?

最好的祝福!

最佳答案

可以调用 instantiateViewControllerWithIdentifier 但如果具有该标识符的 View Controller 不存在,您将返回一个 nil 值。

你可以在你的三个 Storyboard上测试这种方式,直到你找到一个不同于 nil 的值。

Apple documentation

已编辑 :在检测到异常之后(抱歉,Apple 文档有时有点困惑),你可以做的是用这样的 try/catch block 包装你的代码

    @try {
UIViewController *myViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"myViewControllerID"];
}
@catch (NSException *exception) {
DLog(@"Exception: This is not the storyboard");
}
@finally {
DLog(@"I found it!");
}

关于ios - 从 ViewController 标识符中获取 StoryBoard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16502400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com