Creating a UITabBarController using a NIB outside of AppDelegate?

99封情书 提交于 2019-12-05 23:14:24

Unlike other view controllers (e.g. UITableViewController) you should not subclass the UITabViewController. Therefore, unlike you other view controllers, you don't subclass and then make your subclass the owner of the nib, pointing at the view in the nib, with a customised view.

Instead, for whichever class that you want to own your UITabBarController, add a plain, vanilla UITabBarController as an outlet property on this class. (e.g. your app delegate).

Then create a nib file and drag a UITabBarController object into the nib. Set the owner of the nib to be the class that you want to own your tab bar controller (e.g. your app delegate) and connect the outlet you created as a property to the tab bar controller in the nib.

@interface myTabOwningClass

    @property (strong, nonatomic) IBOutlet UITabBarController myTabBarControllerOutlet;

Now at the point you want to create and display your tab bar controller, use the following method:

[[NSBundle mainBundle] loadNibNamed:@"MyTabControllerNib" owner:myTabOwningClass options:nil];

This will initialise the property (i.e. myTabBarControllerOutlet in our example) on the owning class and load the tab bar controller from the nib, including all sub view controllers for each tab etc. that you have defined in the nib.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!