我有一个UITabBar
应用程序的登录屏幕,其中用户分为两类。我想为一种类型的用户显示某个选项卡,为另一种类型的用户显示其他选项卡。有谁知道从哪里开始?
问问题
199 次
1 回答
2
在我的一个应用程序中,我使用此代码在应用程序之间设置tabbarcontroller
首先创建没有tabbarcontroller的登录屏幕
这只是根据您的条件修改的示例在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;
}
在您登录的地方应用以下代码并使用标签栏控制器推送您的控制器
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;
// 在这里写下你的用户条件
if(user == admin){
delegate.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController4, viewController5, viewController7, nil];
}
else{
delegate.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController2, viewController4, viewController5, viewController7, nil];
}
delegate.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController4, viewController5, viewController7, nil];
delegate.tabBarController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController pushViewController:delegate.tabBarController animated:YES];
于 2012-04-06T04:40:51.990 回答