更改主视图控制器中的选项卡栏时如何加载不同的视图控制器?

发布于 2025-01-07 21:55:35 字数 2863 浏览 2 评论 0原文

我正在创建一个 iPad,如 链接。在此例中,当我更改主控端的选项卡时,我需要加载不同的视图控制器。我怎样才能实现这个?我已按如下方式创建了选项卡栏控制器:在 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;
}

这是屏幕截图: 在此处输入图像描述 请分享您的想法。

I am creating an iPad as in the link. In this one I need to load different viewcontrollers when I change the tab in the masterside. How can I implement this? I have created the tabbar controller as follows: in the Appdelegate.m file

- (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;
}

Here is the screen shot: enter image description here
Please share your ideas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能怎样 2025-01-14 21:55:35

你可以使用UITabBarControllerDelegate的方法– tabBarController:didSelectViewController:来知道选择了哪个viewController。然后刷新主视图

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

you may use method – tabBarController:didSelectViewController: of UITabBarControllerDelegate to know which viewController is selected. and you refresh your masterview

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文