gpt4 book ai didi

ios - 一起使用 Nib 和 Storyboard

转载 作者:行者123 更新时间:2023-12-01 19:04:42 25 4
gpt4 key购买 nike

根据我在互联网上阅读的内容, Nib 和 Storyboard在同一个项目中可以相互比较。现在我正在创建一个选项卡式应用程序,并希望执行以下操作:

表 1:用 Nib 构造,

表 2:用 Storyboard构建,

表 3:用 Nib 构造

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

- (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_.xib,我需要拥有 SecondViewController_.storyboard。我该怎么做呢?我可以将名称“SecondViewController_.nib”更改为“SecondViewController_.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; }

最佳答案

您可以按照您的建议创建 Storyboard,然后创建 SecondViewController里面的场景。然后在代码中替换 initWithNibName:调用storyboardWithName:instantiateViewControllerWithIdentifier: .

然而,由于 Storyboard的一个主要特性是能够将多个 Controller 联系在一起并定义它们之间的关系,所以很难想象为什么为一个 Controller 做这件事会是一个好主意。

关于ios - 一起使用 Nib 和 Storyboard ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20458989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com