代码之家  ›  专栏  ›  技术社区  ›  Madhup Singh Yadav

选项卡栏中的uisplitviewcontroller(uitabbarcontroller)?

  •  28
  • Madhup Singh Yadav  · 技术社区  · 15 年前

    在这种情况下,我需要从一个基于选项卡的应用程序开始,在这种情况下,我需要一个或多个选项卡的拆分视图。但似乎无法将拆分视图控制器对象添加到tabbarcontroller。(尽管tabbar对象可以添加到splitviewcontroller)。

    这个问题可以从其他方面看:我在左边有一个全屏,我有一个表视图,当表中的任何行被选中时,弹出窗口应该指向该行。现在,当选择了弹出窗口中的任何行时,该弹出窗口中的行将显示在选定行的左侧(只有该行可见),而另一个弹出窗口将显示在选定行中。(面包屑导航类型)

    我想我已经解释清楚了。伙计们有什么想法或者解决办法吗?

    如果我的问题不清楚,请告诉我。

    谢谢,

    马杜普

    9 回复  |  直到 12 年前
        1
  •  19
  •   g_fred    15 年前

    使用界面生成器,创建拆分视图控制器和选项卡栏控制器,并将它们链接到插座:

    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    @property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
    

    在你的应用程序代理中 didFinishLaunchingWithOption ,将拆分视图控制器分配给选项卡栏控制器:

    splitViewController.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Title" image:nil tag:0] autorelease];
    NSArray *controllers = [NSArray arrayWithObjects:splitViewController,  /* other controllers go here */ nil];
    tabBarController.viewControllers = controllers;
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
    

    这将创建一个选项卡栏控制器(在本例中只有一个选项卡),该控制器在所有方向上都正确显示。

        2
  •  9
  •   Greg Combs    14 年前

    我已经为uisplitviewcontroller编写了一个子类,它将侦听设备方向的更改并相应地调整自身的方向。有了这个类,我现在可以将拆分视图放在uitabbarcontroller中,并且每个拆分视图在旋转时都将正确工作,即使它不是最前面的选项卡。我已经成功地在 TexLege 它被批准在应用程序商店中使用,但您的里程可能会有所不同。请查看github上的存储库。

    你可以随意改变它,我总是对听到关于它的评论(或抱怨)感兴趣。 https://github.com/grgcombs/IntelligentSplitViewController

        3
  •  7
  •   Madhup Singh Yadav    12 年前

    我做了一个样本申请。发现我们可以通过编程的方式来完成,比如:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
            NSMutableArray *array = [NSMutableArray array];
    
            NSMutableArray *tabArray = [NSMutableArray array]; 
    
            UISplitViewController *splitViewConntroller = [[UISplitViewController alloc] init];
    
            MainViewController *viewCont = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
            [array addObject:viewCont];
            [viewCont release];
    
            viewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
            [array addObject:viewCont];
            [viewCont release];
    
    
    
    
            [splitViewConntroller setViewControllers:array];
    
            [tabArray addObject:splitViewConntroller];
    
            [splitViewConntroller release];
    
            array = [NSMutableArray array];
    
            splitViewConntroller = [[UISplitViewController alloc] init];
    
            viewCont = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
            [array addObject:viewCont];
            [viewCont release];
    
            viewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
            [array addObject:viewCont];
            [viewCont release];
    
            [splitViewConntroller setViewControllers:array];
    
            [tabArray addObject:splitViewConntroller];
    
            [splitViewConntroller release];
    
            // Add the tab bar controller's current view as a subview of the window
            [tabBarController setViewControllers:tabArray];
    
            [window addSubview:tabBarController.view];
            [window makeKeyAndVisible];
    
            return YES;
        }
    

    希望这有帮助。

        4
  •  2
  •   Yan Cheng    15 年前

    要让tabbarcontroller显示为splitviewcontroller的主视图,应该重写tabbarcontroller,使其支持或定向(例如,使用uitabbarcontroller类的类别)

        5
  •  2
  •   user318668    15 年前

    请参阅关于将拆分视图控制器改装为现有选项卡栏界面的文章: http://markivsblog.blogspot.com/2010/04/retrofitting-ipad-uisplitviewcontroller.html

        6
  •  2
  •   Brody Robertson    12 年前

    我创建了一个uitabbarcontroller子类,该子类将旋转消息正确地传播到它包含的所有uisplitviewcontroller。这将保持uisplitviewcontroller的正确内部状态。但是,如果splitviewcontroller不可见,则不会调用splitviewcontroller委托方法之一,因此我在详细视图控制器viewwillappear方法中对此进行了说明。我已经在ios5.0-ios6.1中确认了这一点

    ostabbarcontroller.m

    #import "OSTabBarController.h"
    
    @implementation OSTabBarController
    
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
        for(UIViewController *targetController in self.viewControllers){
            if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]]){
                [targetController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
            }
        }
    }
    
    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
        [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
        for(UIViewController *targetController in self.viewControllers){
            if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]]){
                [targetController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
            }
        }
    }
    
    @end
    

    详细视图控制器

    @implementation OSDetailViewController
    
    -(void)viewWillAppear:(BOOL)animated{
        //the splitViewController:willHideViewController:withBarButtonItem:forPopoverController: may not have been called
        if(!UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
            self.navigationItem.leftBarButtonItem = nil;
        }
    }
    
    #pragma mark - UISplitViewControllerDelegate Methods
    
    - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
    {
        [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
    
    }
    
    - (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
    {
        [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    }
    
    @end
    
        7
  •  1
  •   Jason    14 年前

    请记住,OS3.2可以 没有提供适当的支持 作为选项卡栏视图的拆分视图。

    你可以让它“工作”,但它会有错误-最大的错误是,在另一个选项卡的视图上所做的方向更改通常不会正确地传播到SplitView选项卡视图,当你返回到它时会使视图变得古怪(左侧视图接管屏幕,或者缺少Barbutton项,eTC)。

    我得出的结论是,由于这个问题,我必须创建自己的splitview,以便在tabbarcontroller中使用。

    我听说苹果正在进行修复,但是已经几个月了,没有ipad操作系统的更新,也许ipad的os 4会解决这个问题。

        8
  •  0
  •   mikezang    14 年前

    您可以使用ib构建tabtab,并将tab修改为splitviewcontroller。

    -(void) makeSplitViewController {
    NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
    int index = 0;
    
    for (UIViewController *controller in tabBarController.viewControllers) {
        if ([controller.tabBarItem.title isEqualToString:@"Stock"]) {
            stockDetailController = [[StockDetailController alloc] initWithNibName:@"StockDetailController" bundle:nil];
    
            stockMasterController = [[StockMasterController alloc] initWithStyle:UITableViewStylePlain]; 
            stockMasterController.navigationItem.title = date;
            stockMasterController.stockDetailController = stockDetailController;
    
            UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:stockMasterController] autorelease];
    
            splitViewController = [[UISplitViewController alloc] init];
            splitViewController.tabBarItem = controller.tabBarItem;
            splitViewController.viewControllers = [NSArray arrayWithObjects:nav, stockDetailController, nil];
            splitViewController.delegate = stockDetailController;
    
            [controllers replaceObjectAtIndex:index withObject:splitViewController];
        }
    
        index++;
    }
    
    tabBarController.viewControllers = controllers;
    

    }

        9
  •  0
  •   zontar    12 年前

    我们成功地在带有ios5+的ipad上的uitabviewcontroller中安装了uisplitviewcontroller。

    长话短说:它起作用:

    • 开箱即用,如果你接受分割也在肖像;
    • 有点 工作,如果你想让主视图隐藏在纵向,并且 只要按一下按钮它就会出现。

    第二种情况下的诀窍是使用intelligentsplitviewcontroller(参见上面的几篇文章,thanx greg combs)或类似地扩展uisplitvc,并注意splitview控制器的子类的委托始终是一个活动对象。

    我们详细介绍了以下过程:

    https://devforums.apple.com/message/763572#763572