简体   繁体   English

如何将UITabBarController设置为View?

[英]How to set UITabBarController to View?

I have an app that have several views. 我有一个有几个视图的应用程序。 In one view I would like to add a UITabBarController . 在一个视图中,我想添加一个UITabBarController

In another app I used this to add the UITabBarController to the rootViewController , but I am not sure if that is even the correct way to do it. 在另一个应用程序中,我使用rootViewController UITabBarController添加到rootViewController ,但我不确定这是否是正确的方法。

in the .h 在.h

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

in the .m 在他们中

@synthesize tabBarController=_tabBarController;
self.window.rootViewController = self.tabBarController;

In one of my app i have used this code to set tabbarcontroller in between app 在我的一个应用程序中,我使用此代码在app之间设置tabbarcontroller

define tabbar controller in AppDelegate.m 在AppDelegate.m中定义tabbar控制器

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate=self;
self.tabBarController.selectedIndex=0;
self.tabBarController.delegate=self;


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
//NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewController];

  // return YES;
}

Apply below code where you want to push your controller with tab bar controller 在下面的代码中应用您想要使用标签栏控制器推动控制器的代码

AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UIViewController *viewController1 = [[GeneralViewController alloc] initWithNibName:@"GeneralViewController" bundle:nil];
    UIViewController *viewController2 = [[MiscQuotationController alloc] initWithNibName:@"MiscQuotationController" bundle:nil];
    UIViewController *viewController4 = [[QuotationListController alloc] initWithNibName:@"QuotationListController" bundle:nil];
    UIViewController *viewController5 = [[ChargesViewController alloc] initWithNibName:@"ChargesViewController" bundle:nil];
    UIViewController *viewController7 = [[SalesPartViewController alloc] initWithNibName:@"SalesPartViewController" bundle:nil];

    ///   tab button title
    viewController1.title = @"Basic information";
    viewController2.title = @"Misc Quotation";
    viewController4.title = @"Quotation Line";
    viewController5.title = @"Charges";
    viewController7.title = @"Sales Part Stock";

    // tab button Images
    viewController1.tabBarItem.image = [UIImage imageNamed:@"general.png"];
    viewController2.tabBarItem.image = [UIImage imageNamed:@"misle.png"];
    viewController4.tabBarItem.image = [UIImage imageNamed:@"history.png"];
    viewController5.tabBarItem.image = [UIImage imageNamed:@"charges.png"];
    viewController7.tabBarItem.image = [UIImage imageNamed:@"shoebox.png"];

    delegate.tabBarController = [[UITabBarController alloc] init];
    delegate.tabBarController.selectedIndex = 0;
    delegate.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController4, viewController5, viewController7, nil];
    delegate.tabBarController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self.navigationController pushViewController:delegate.tabBarController animated:YES];

Instead of writing this 而不是写这个

self.window.rootViewController = self.tabBarController;

Write this in the code: 在代码中写下:

[self.window addSubview:self.tabBarController.view];

You cannot add UITabbarController to UIViewController , but you can add UITabBar to UIViewController's view. 您不能将UITabbarController添加到UIViewController ,但您可以将UITabBar添加到UIViewController's视图中。

Hope this might help you....... 希望这可能对你有帮助.......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为包含UITabBarController的UIViewController设置视图出口? - How to set view outlet for a UIViewController that contains a UITabBarController? 如何在UITabBarController上设置另一个视图的对象的.hidden属性 - How can I set the .hidden property of an object of another view on a UITabBarController 如何使用UITabBarController在applicationDidBecomeActive上显示视图 - How to display view on applicationDidBecomeActive with UITabBarController UITabBarController - 如何访问视图控制器? - UITabBarController - How to access a view controller? TabBarController进入视图时如何设置UITabBarController不选择任何选项卡(ViewController) - How to Set UITabBarController to not select any Tab (ViewController) when TabBarController comes to View 添加UITabBarController之前如何显示登录或注册之类的导航控制器(视图控制器集) - How to display navigation controller (set of view controllers) such as login or register before adding UITabBarController 如何使UITabBarController懒惰地加载视图控制器? - How to make UITabBarController load view controllers lazily? 如何在UINavigationController和UITabBarController内部翻转视图(使用UIModalTransitionStyleFlipHorizo​​ntal) - How to Flip a view (with UIModalTransitionStyleFlipHorizontal) inside UINavigationController and UITabBarController 如何强制 UITabBarController 内部视图的水平方向? - How to force horizontal orientation for a view inside of a UITabBarController? 如何指定UITabBarController要使用的视图控制器类? - How to specify the view controller classes to be used by UITabBarController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM