一起使用笔尖和情节提要 [英] Using nibs and storyboards together

查看:96
本文介绍了一起使用笔尖和情节提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我在互联网上阅读的内容,笔尖和情节提要在同一项目中彼此具有可比性.现在,我正在创建一个选项卡式应用程序,并希望执行以下操作:

From what I have read on the internet, nibs and storyboards are comparable with each other in the same project. Now I am creating a tabbed application and would like to do the following:

标签1:用笔尖构造的

选项卡2:使用情节提要构建,

Tab 2: constructed with storyboards,

标签3:用笔尖构造

最初,我用笔尖创建了所有内容,因此在我的委托中,我使用以下代码从一个选项卡传递到了另一个选项卡:

Initially I created everything with nibs so in my delegate I was passing from one tab to the next with this code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    UIViewController *viewController1, *viewController2, *viewController3;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
        viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
        viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPhone" bundle:nil] autorelease];
    } else {
        viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPad" bundle:nil] autorelease];
        viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPad" bundle:nil] autorelease];
        viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPad" bundle:nil] autorelease];

    }
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;



}

我需要拥有SecondViewController _ .storyboard,而不是拥有SecondViewController_ .xib.我该怎么做呢?我可以仅将名称"SecondViewController_ .nib"更改为"SecondViewController _ .storyboard"吗?我认为这行不通.

Instead of having the SecondViewController_.xib I need to have the SecondViewController_.storyboard. How do I do this? Can I just change the name "SecondViewController_.nib" to "SecondViewController_.storyboard"? I don't think this would work..

任何帮助将不胜感激!!

Any help would be very appreciated!!

我正在使用的代码:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Events", @"Events");
        self.tabBarItem.image = [UIImage imageNamed:@"second"];
    }
    return self; }

推荐答案

您可以通过创建一个情节提要,然后在其中创建一个SecondViewController场景来执行建议的操作.在代码中,然后将initWithNibName:替换为对storyboardWithName:instantiateViewControllerWithIdentifier:的调用.

You could do what you're suggesting by creating a storyboard and then creating a SecondViewController scene inside it. In code, you would then replace initWithNibName: with calls to storyboardWithName: and instantiateViewControllerWithIdentifier:.

但是,由于情节提要板的主要功能是能够将多个控制器绑定在一起并定义它们之间的关系,因此很难想象为什么对一个控制器执行此操作会是个好主意.

However, since a major feature in storyboards is the ability to tie multiple controllers together and define relationships between them, it's hard to imagine why doing it for one controller would be a good idea.

这篇关于一起使用笔尖和情节提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆