gpt4 book ai didi

ios - 更改主视图 Controller 中的选项卡栏时如何加载不同的 View Controller ?

转载 作者:行者123 更新时间:2023-11-29 13:40:11 26 4
gpt4 key购买 nike

我正在创建一个 iPad,如 link .在这一个中,当我更改 masterside 中的选项卡时,我需要加载不同的 View Controller 。我该如何实现?我按如下方式创建了标签栏 Controller :在 Appdelegate.m 文件中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

tabBarController = [[UITabBarController alloc] init];

StudentVC *stdntVC = [[[StudentVC alloc]initWithNibName:@"StudentVC" bundle:nil] autorelease];
TeachersVC *teachersVC = [[[TeachersVC alloc]initWithNibName:@"TeachersVC" bundle:nil] autorelease];
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil] autorelease];
ConfigurationVC *configViewController = [[[ConfigurationVC alloc] initWithNibName:@"ConfigurationVC" bundle:nil] autorelease];

UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
UINavigationController *studentNavigationController = [[[UINavigationController alloc] initWithRootViewController:stdntVC] autorelease];
UINavigationController *teacherNavigationController = [[[UINavigationController alloc] initWithRootViewController:teachersVC] autorelease];
UINavigationController *configNavigationController = [[[UINavigationController alloc] initWithRootViewController:configViewController] autorelease];

NSArray* controllers = [NSArray arrayWithObjects:studentNavigationController,teacherNavigationController,masterNavigationController, configNavigationController, nil];
tabBarController.viewControllers = controllers;

ShowDetailsVC *showViewController = [[[ShowDetailsVC alloc] initWithNibName:@"ShowDetailsVC" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:showViewController] autorelease];


self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = [NSArray arrayWithObjects:tabBarController, detailNavigationController, nil];

self.splitViewController.delegate = showViewController;

self.window.rootViewController = self.splitViewController;

stdntVC.detailsVC = showViewController;
teachersVC.detailsVC = showViewController;
masterViewController.detailsVC = showViewController;
configViewController.detailsVC = showViewController;

[self.window makeKeyAndVisible];

return YES;
}

这是屏幕截图:enter image description here请分享您的想法。

最佳答案

您可以使用 UITabBarControllerDelegate 的方法 – tabBarController:didSelectViewController: 来了解选择了哪个 viewController。然后你刷新你的 masterview

https://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html

关于ios - 更改主视图 Controller 中的选项卡栏时如何加载不同的 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9390451/

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