[英]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.