gpt4 book ai didi

ios - 将各个 View 放入选项卡的最佳方式

转载 作者:行者123 更新时间:2023-11-29 03:16:38 25 4
gpt4 key购买 nike

我是一名初学者 ios 程序员,并且构建了一个不使用 Storyboard的应用程序。不同的观点有不同的 Nib 。它还有一个委托(delegate)文件。

如果我想从一个 View 切换到另一个 View ,我在 View Controller 中使用这段代码。

self.detailController = [[[DetailController alloc]
initWithNibName:@"DetailController" bundle:nil] autorelease];
self.detailController.originalObj = nil;

SUP101AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navController pushViewController:self.detailController animated:YES];

应用程序在委托(delegate)中也有以下代码来显示初始 View

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

self.viewController = [[[SubscribeController alloc] initWithNibName:@"SubscribeController" bundle:nil] autorelease];
self.navController = [[[UINavigationController alloc] initWithRootViewController: self.viewController] autorelease];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;

}

我想更改应用程序,以便每个 View 都显示在一个选项卡中,并且从一个 View 切换到另一个 View 应该在选项卡中进行。我尝试了其他帖子中的几个示例,但无法逐步解决如何为这个现有应用程序实现基于选项卡的 View 。我不确定我应该使用 xcode 中的新文件添加选项卡 Controller 还是以编程方式在 View Controller 中制作选项卡。或者我应该从一个基于选项卡的新项目开始并将我的旧项目文件复制到其中......请建议。

最佳答案

这是您修改后的代码,用于启动带有 4 个标签的标签栏 Controller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

UIViewController *VC1=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name
VC1.title=@"VC1";
UINavigationController *NC1=[[UINavigationController alloc] initWithRootViewController:VC1];//set root of navigation controller
UIViewController *VC2=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name
VC2.title=@"VC2";
UINavigationController *NC2=[[UINavigationController alloc] initWithRootViewController:VC2];//set root of navigation controller
UIViewController *VC3=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name
VC3.title=@"VC3";
UINavigationController *NC3=[[UINavigationController alloc] initWithRootViewController:VC3];//set root of navigation controller
UIViewController *VC4=[[UIViewController alloc] initWithNibName:nil bundle:nil];//set you nib name
VC4.title=@"VC4";
UINavigationController *NC4=[[UINavigationController alloc] initWithRootViewController:VC4];//set root of navigation controller

UITabBarController *tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:@[NC1,NC2,NC3,NC4]];

[self.window setRootViewController:tabBarController];

[self.window makeKeyAndVisible];
return YES;
}

关于ios - 将各个 View 放入选项卡的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21613347/

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