简体   繁体   English

将XIB视图添加到故事板中的选项卡视图

[英]Add a XIB view to a tab view in the storyboard

I am working on an Iphone application. 我正在研究Iphone应用程序。 I am using a StoryBoard. 我正在使用StoryBoard。

I have a Tab View with 3 tabs. 我有一个带有3个标签的标签视图。 "Home", "Users" and "Settings". “主页”,“用户”和“设置”。

I create the "Home" and "Users" view on the story board, but The settings view is a XIB file (SettingsView.xib) 我在故事板上创建了“Home”和“Users”视图,但是设置视图是一个XIB文件(SettingsView.xib)

How can I make the third tab ("Settings") open the SettingsView.xib? 如何使第三个选项卡(“设置”)打开SettingsView.xib? Can I use both the story board and xib files? 我可以同时使用故事板和xib文件吗?

I tried to initialize a UINavigationController in the startApp method in the AppDelegate but I can't find out how to add it to the story board. 我试图在AppDelegate的startApp方法中初始化UINavigationController ,但我无法找到如何将它添加到故事板。

Thanks for any help 谢谢你的帮助

TabViewControllers usually have one navigation controller for each tab. TabViewControllers通常为每个选项卡都有一个导航控制器。 Create the navigation controllers in storyboard and connect them to the navigationcontrollers relation of the tab view controller. 在故事板中创建导航控制器,并将它们连接到选项卡视图控制器的navigationcontrollers关系。

The initial view of the navigation controller connects to the rootViewController relationship of the navigation controller. 导航控制器的初始视图连接到导航控制器的rootViewController关系。

As to your second question, I'm not certain, but I think the following will work:- 至于你的第二个问题,我不确定,但我认为以下内容可行: -

Create a UIViewController in storyboard and change it's class to your class that you're loading from an XIB. 在故事板中创建一个UIViewController,并将它的类更改为您从XIB加载的类。 When the storyboard instantiates the class, it will use the XIB provided the class name of the class exactly matches the name of the XIB. 当故事板实例化该类时,它将使用XIB,前提是该类的类名与XIB的名称完全匹配。 I don't think you can do any iPad/iPod checking here though. 我不认为你可以在这里做任何iPad / iPod检查。

You can add a xib-based view to your storyboard-based tab bar controller as follows. 您可以将基于xib的视图添加到基于故事板的选项卡栏控制器,如下所示。 I am assuming the following: 我假设以下内容:

  • The tab bar controller is the initial view controller of your storyboard. 标签栏控制器是故事板的初始视图控制器。
  • Your settings controller is a class called SettingsController 您的设置控制器是一个名为SettingsController的类
  • You have a tab bar image in your bundle called SettingsTabImage 您的捆绑包中有一个名为SettingsTabImage的标签栏图像

Define the tab bar controller in the storyboard with just your storyboard-based tab bar items in it - Home and Users in your case 在故事板中定义标签栏控制器,只包含基于故事板的标签栏项目 - 您的案例中的主页和用户

In your application delegate, use the following code in application:didFinishLaunchingWithOptions: : 在您的应用程序委托中,在application:didFinishLaunchingWithOptions:使用以下代码application:didFinishLaunchingWithOptions: ::

// Create your settings view controller
SettingsController *settingsVC = [[SettingsController alloc] initWithNibName:nil bundle:nil];

// Create a tab bar item
UITabBarItem *settingsItem = [[UITabBarItem alloc] initWithTitle:@"Settings" image:[UIImage imageNamed:@"SettingsTabImage" tag:0];
settingsVC.tabBarItem = settingsItem;

// Get a reference to the tab bar controller
UITabBarController *tbC = (UITabBarController*)self.window.rootViewController;

// Get the current view controllers in your tab bar
NSMutableArray *currentItems = [NSMutableArray arrayWithArray:tbC.viewControllers];

// Add your settings controller
[currentItems addObject:settingsVC];
tbC.viewControllers = [NSArray arrayWithArray:currentItems];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM