如何将UITabBarController设置为View? [英] How to set UITabBarController to View?
本文介绍了如何将UITabBarController设置为View?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有几个视图的应用。在一个视图中,我想添加一个 UITabBarController
。
I have an app that have several views. In one view I would like to add a UITabBarController
.
在另一个应用程序中,我用它来添加 UITabBarController
到 rootViewController
,但我不确定这是否是正确的方法。
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.
在.h
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
在.m
@synthesize tabBarController=_tabBarController;
self.window.rootViewController = self.tabBarController;
推荐答案
在我的一个应用程序中,我使用了此代码在app之间设置tabbarcontroller
In one of my app i have used this code to set tabbarcontroller in between app
在AppDelegate.m中定义tabbar控制器
define tabbar controller in AppDelegate.m
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];
这篇关于如何将UITabBarController设置为View?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文