在代码中决定在应用程序启动时加载哪个类和 xib 文件
我正在更改我的应用程序以添加应用程序内购买。当我最初设置应用程序时,我使用了界面生成器,但现在我需要决定使用哪个类和类。 xib 文件根据用户是否购买了某项功能在应用程序启动时加载。
我的应用程序设置了一个选项卡栏控制器,每个选项卡都有一个 naviagion 控制器。在 MainWindow.xib 文件中,我告诉 IB 使用 HomeView.xib 和 HomeView 类。现在我需要检查是否已购买某个功能并加载 HomeView 或 HomeView2。我不知道应用程序中的哪个位置告诉 naviagionController 要加载哪个类和视图,因为我之前在界面生成器中设置了所有这些。
我可以在 HomeViewNavigationController 中做出这个决定,而不是 IB 自动为我做出这个决定吗?
预先感谢您的帮助!
I'm changing my app to add an in app purchase. When I initially set up the app I used interface builder but now i need to decide which class & xib file to load on app launch based on whether or not a user has purchased a feature.
My app is set up with a tab bar controller that has a naviagion controller for each tab. Inside the MainWindow.xib file I've told IB to use the HomeView.xib and HomeView class. Now I need to check if a feature has been purchased and load either HomeView or HomeView2. I don't know where in the app to tell the naviagionController which class and view to load as I previously set all this up in interface builder.
Can I make this decision inside the HomeViewNavigationController instead of IB automatically making this decision for me?
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
保持简单。
在 HomeView.xib 中,有两个可以加载的不同视图。让 xib 中的 UIViewController 视图成为“容器视图”。在 HomeView 控制器的 viewDidLoad 中执行检测代码,然后添加适当的视图作为子视图。
Keep it simple.
In HomeView.xib, have two different views you can load. Have the view of the UIViewController in the xib be the "container view". Do your detection code in the viewDidLoad of your HomeView controller and then add the proper view as a subview.
您可以在 Info.plist 中设置要加载的 xib。在启动时系统将自动加载此 xib。虽然更改 Info.plist 文件中的 xib 名称很容易,但它会被 Apple 拒绝。
这就是我要做的:不要使用 xibs,至少对于你提到的两个。相反,在 applicationDidFinishLaunching:(NSNotification *)notification 中创建所有内容
You set the xib you want to load in your Info.plist. At launch time the system will automatically load this xib. While its easy to change the xib name in the Info.plist file, it'll get rejected by Apple.
Here's what I would do: don't use xibs, at least for the two you mentioned. Instead, create everything in applicationDidFinishLaunching:(NSNotification *)notification