如何在更改主视图控制器中的选项卡时加载不同的视图控制器?
我正在创建一个iPad,如link。在这个我需要加载不同的视图控制器,当我改变主界面的选项卡。我怎样才能实现这个?我创建了的TabBar控制器如下:在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;
}
这里是截屏: 请分享您的想法。
您可以使用UITabBarControllerDelegate
的方法– tabBarController:didSelectViewController:
来知道选择哪个viewController。并刷新你的主视图
但我应该在哪里添加此代码?在appdelegate文件中?以及如何刷新masterview? – Mithuzz 2012-02-22 08:49:05
你可以在appdelegate中创建你的tabBar,你可以将这个方法添加到你的应用程序委托中,并且确保你的appdelegate定义为'UITabBarControllerDelegate',将这个协议推送到你的.h文件并且添加'tabBarController.delegate = self;'到你的代码中。 – Alkimake 2012-02-22 08:53:16
想要了解更多关于协议的信息(代表),请看http://iphonedevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html – Alkimake 2012-02-22 08:53:50
你能发表截图吗? – user523234 2012-02-22 08:31:31
我已添加,请现在检查。 – Mithuzz 2012-02-22 08:42:32