ios - 如何检查 Storyboard 是否存在于特定的 NSBundle 中

标签 ios objective-c xcode storyboard nsbundle

我正在制作一个应用,该应用使用我正在创建的框架。

框架包含 Storyboard,但在某些情况下,使用框架的项目需要通过提供新 Storyboard来覆盖 Storyboard。

所以我的目标是检查 [NSBundle mainBundle] 中是否存在具有给定名称的 Storyboard,如果不存在,那么我将从我的框架中获取基础版本。

我已经尝试从主包中获取 Storyboard并检查结果是否为 nil,但如果找不到它就会抛出异常。所以我然后 try catch 异常,然后从框架加载 Storyboard。这确实有效,但感觉很脏,很可能会影响我的应用程序的性能。

我还在包中尝试了 pathForResource:

if([[NSBundle mainBundle] pathForResource:name ofType:@"storyboard"] != nil) {

}

但这永远找不到 Storyboard。

有谁知道我可以检查特定包中是否存在 Storyboard的任何其他方法?

最佳答案

所以,我几乎已经完成了我已经尝试过的事情。根据对我的问题的评论, Storyboard的编译扩展名是“storyboardc”。所以我可以像这样检查一个 Storyboard是否存在于一个包中:

if([[NSBundle mainBundle] pathForResource:name ofType:@"storyboardc"] != nil) {
    //The storyboard exists
} else {
    //The storyboard isn't in the bundle, get it from the framework bundle.
}

关于ios - 如何检查 Storyboard 是否存在于特定的 NSBundle 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38590288/

相关文章:

ios - UIScrollView的 "pull up to load more"和 “pull down to go back"导致闪烁(附示例代码)

iphone - 我如何在弹出 View Controller 上做一个翻转动画?

objective-c - 使用未声明的标识符 ' IKImageBrowserNSURLRepresentationType'

ios - 无法创建class的实例,导致应用崩溃

ios - 在 iPhone 应用程序中打开 iBooks

iphone - 制作类似于会说话的汤姆猫的应用程序

json - 如何在以下代码中访问 __nssingleobjectarrayi 的值

objective-c - "Failed to unarchive element named UITableViewController"

ios - 在 swift 中为所有出现的字符串着色

iphone - 如何在 Xcode 4.5 中将内容连接到不同页面。 iOS 6