我有一个旧项目,将其视图实现为xibs。视图是带有标签栏的控制器。
现在,我想添加一个新的UITabBarItem,但是我希望这个新项目不是基于xib的,而是基于Storyboard的。意思是,我只想将一个故事板用于此选项卡项的内容,而将应用程序的其余部分保持原样。
我做了以下事情:
创建了新的故事板
创建了一个新的ViewController,应该用作情节提要的包装器
然后我将选项卡IB中的基础VC更改为新的VC
但是我现在该如何进行呢?我试图这样做,使InitialViewController成为Tab的ViewCOntroller:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
UIStoryboard *financeStoryboard = [UIStoryboard storyboardWithName:@"WS_Finanzierung_Storyboard_iPhone" bundle:nil];
UIViewController * initialViewController = [financeStoryboard instantiateInitialViewController];
[self presentViewController:initialViewController animated:YES completion:nil];
}
return self;
}
但是它不起作用(崩溃了。。。)
问:那是正确的方法吗?有最佳做法吗?
提前致谢
最佳答案
试试这个
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[StoryViewController alloc] init];
UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
viewController3 = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"newTab"];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
这样分配情节提要标识符->
并取消选中初始视图控制器->
输出ll像这样..
关于iphone - 将Storyboard实例化为TabBarItem,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18380309/