gpt4 book ai didi

iphone - 第二 View 中的标签栏

转载 作者:行者123 更新时间:2023-11-28 22:43:23 25 4
gpt4 key购买 nike

我的应用程序中有一个激活页面,每个用户都必须激活该页面才能激活该应用程序。一旦应用程序被激活,用户就会移动到标签栏 View 。

我已经创建了一个选项卡式栏应用程序,从我的 activationView 单击按钮我试图调用选项卡栏,我得到一个整个黑屏。

- (IBAction)moveToActivateView:(id)sender {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
[self.view addSubview:tabBarController.view];
appDelegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

self.tabBarController.viewControllers = @[viewController1, viewController2];
appDelegate.window.rootViewController = self.tabBarController;
[appDelegate.window makeKeyAndVisible];}

最佳答案

嘿,在 appDelegate 中创建你的 tabBarController 属性,并在那里分配所有 ViewController,然后从你的 ViewController 调用你的 tabBarController

在 AppDelegate.h 中

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (retain, nonatomic) IBOutlet UITabBarController *tabBarController;

在 AppDelegate.m 中

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

[self makeTabBar];

[self addInitialVIew];

[self.window makeKeyAndVisible];

return YES;
}


-(void)makeTabBar
{
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
FirstViewController *firstVC =[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

UINavigationController *firstNC = [[UINavigationController alloc] initWithRootViewController:firstVC];
firstNC.tabBarItem.title=@"Profile";
firstVC.tabBarController.tabBar.tag = 0;


SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

UINavigationController *SecondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];
SecondNavController.tabBarItem.title = @"Search";
secondVC.tabBarController.tabBar.tag = 1;


NSArray *viewControllers =[[NSArray alloc]initWithObjects:firstNC,SecondNavController, nil];
[tabBarController setViewControllers:viewControllers animated:NO];
}

-(void) addInitialVIew
{
InitialViewController *initialViewController = [[InitialViewController alloc]initWithNibName:@"InitialViewController" bundle:nil];
navigationController = [[UINavigationController alloc]initWithRootViewController:ViewController];
[self.window addSubview:navigationController.view];
}

现在在 InitialViewController 中,您可以添加 TabBar 并删除 InitialViewController

- (IBAction)switchToTabBarBtnPress:(id)sender
{
AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];

[[[appdelegte navigationController] view]removeFromSuperview];

[[appdelegte window]addSubview:[[appdelegte tabBarController]view]];

[[appdelegte tabBarController]setSelectedIndex:0];
}

然后按照我的回答

Answer

关于iphone - 第二 View 中的标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13856933/

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