Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 同时使用笔尖和故事板_Ios_Storyboard_Uitabbarcontroller_Xib_Nib - Fatal编程技术网

Ios 同时使用笔尖和故事板

Ios 同时使用笔尖和故事板,ios,storyboard,uitabbarcontroller,xib,nib,Ios,Storyboard,Uitabbarcontroller,Xib,Nib,从我在互联网上读到的内容来看,在同一个项目中,NIB和故事板是可以相互比较的。现在,我正在创建一个选项卡式应用程序,并希望执行以下操作: 表1:用笔尖构造 表2:用故事板构建 表3:用笔尖构造 最初,我使用NIB创建了所有内容,因此在我的委托中,我使用以下代码从一个选项卡传递到下一个选项卡: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOp

从我在互联网上读到的内容来看,在同一个项目中,NIB和故事板是可以相互比较的。现在,我正在创建一个选项卡式应用程序,并希望执行以下操作:

表1:用笔尖构造

表2:用故事板构建

表3:用笔尖构造

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

- (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_uxib,而是SecondViewController_xib.storyboard。我该怎么做?我能把名字“SecondViewController_uu.nib”改成“SecondViewController_uu.storyboard”吗?我认为这行不通

任何帮助都将不胜感激

编辑: 我使用的代码是:

- (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:
实例化eviewcontrollerwhiteIdentifier:


然而,由于故事板的一个主要功能是能够将多个控制器连接在一起并定义它们之间的关系,很难想象为什么为一个控制器这样做会是一个好主意。

正如Phillip所说,只需使用
实例化eviewController标识符即可

- (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;
    UIStoryboard *storyboard;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
        storyboard      = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
        viewController2 = [storyboard instantiateViewControllerWithIdentifier:@"Second"];
        viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPhone" bundle:nil] autorelease];
    } else {
        viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPad" bundle:nil] autorelease];
        storyboard      = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
        viewController2 = [storyboard instantiateViewControllerWithIdentifier:@"Second"];
        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;
}
这假设您的故事板被称为
iPhone.storyboard
iPad.storyboard
,但更改上述代码以匹配您所称的这两个故事板。此外,这再次假设您将该场景定义为具有
秒的“情节提要ID”(您可以通过在IB中选择视图控制器并转到“标识检查器”来执行此操作),并且您也在其中指定了“自定义类”:


对于
SecondViewController
,应将
initWithNibName:bundle:
方法替换为:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if (self) {
        self.title = NSLocalizedString(@"Events", @"Events");
        self.tabBarItem.image = [UIImage imageNamed:@"second"];
    }

    return self; 
}

谢谢你的评论,菲利普!恐怕我不明白我需要做什么。。首先,“在内部创建第二个ViewController场景”是什么意思?我必须用“InstanceViewController Withindentifier:”替换什么?1)将视图控制器放入情节提要时,它会创建一个与类型或控制器子类匹配的“场景”。因此,“SecondViewController场景”是将视图控制器设置为
SecondViewController
的场景之一。2) 您当前调用
initWithNibName:@“SecondViewController\u iPhone”
…我是说您需要删除它并调用其他两个方法。好的,第1部分很清楚。现在唯一的问题是第二部分。我应该把名为的故事板放在哪里?我应该把InstanceEviewController和Identifier放在哪里?@DCB你应该接受Phillip的答案(点击旁边的复选标记),甚至可以投票。我必须说,如果你原谅这篇社论,请看@DCB。虽然上面的技术向你展示了如何将故事板和笔尖结合起来,但我建议你还是继续向故事板过渡。如果你一开始就把所有的事情都转移到故事板上,你可能会浪费更多的时间来想办法让两者共存。太棒了!谢谢现在我有一个问题出现了。。在底部的选项卡栏上,我不再有选项卡的图标或名称。。在此之前,我用特定的代码调用它。这不起作用,因为它使用了笔尖。我该如何解决这个问题?(我已经用我使用的代码更新了这个问题)@DCB对于基于故事板的视图控制器(第二个),使用
initWithCoder
而不是
initWithNibName
。但是在my.h中,我现在有了-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];如果(self){//Initialization code}返回self;}@DCB是否确认场景的视图控制器基类已设置为
SecondViewController
(请参见上面的identity inspector屏幕快照)?可能将断点放在
initWithCoder
(将控制器添加到选项卡栏控制器时将调用该断点)和
viewDidLoad
(在第二个选项卡上进行选项卡时将调用该断点)并确认视图控制器得到了正确的实例化。但我确认这种技术工作得很好,所以您一定忽略了项目中的一些简单内容。