从自定义框架访问故事板不起作用 [英] Accessing storyboard from custom framework not working
问题描述
我必须从应用程序委托中的自定义框架(LoginUIModule、LoginUIModule 具有故事板 LoginScreen.storyboard)访问故事板.我从主界面中删除了主故事板,也从主故事板文件基本名称中删除了名称以及 .plist,但我收到一个错误
Hi I have to access storyboard from custom framework (LoginUIModule, LoginUIModule have storyboard LoginScreen.storyboard) in app delegate. I removed Main storyboard from Main Interface and also removed name from Main storyboard file base name as well from .plist, but I getting an error
原因:在捆绑 NSBundle 中找不到名为LoginScreen"的情节提要
注意:- LoginUIModule 是单独的模块,我需要在我的主 (OneAppllbs) 项目中访问它,这又是一个单独的模块
Note:- LoginUIModule is separate Module and I need to access it in my main (OneAppllbs) project which is a again separate module
我在应用委托中使用的代码
The Code which I used in app delegate
import LoginUIModule
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "LoginScreen", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "LoginUIModuleViewController") as? LoginUIModuleViewController
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
推荐答案
您需要设置Bundle
才能访问Storyboard.
You need set Bundle
to access Storyboard.
首先使用Bundle Identifier为框架创建storyboardBundle;
First create storyboardBundle with Bundle Identifier for framework;
let storyboardName = "LoginScreen"
let storyboardBundle = Bundle(for: LoginUIModuleViewController.self)
或引用框架中的类:
let storyboardBundle = Bundle(identifier: "com.yourframework.id")
然后用这个包创建故事板:
Then create storyboard with this bundle:
let storyboard = UIStoryboard(name: storyboardName, bundle: storyboardBundle)
这篇关于从自定义框架访问故事板不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!