【发布时间】:2014-07-24 03:07:43
【问题描述】:
在我的项目中,我通过编程方式创建 TabBarController。
有2个标签栏。(构造列表标签和设置标签)
在设置选项卡中,当推送到下一个视图控制器(例如 ChangePassword)时它起作用了。
但是在 ChangePassword ViewController 中,当触摸 Tab Setting View 时会变为 Setting Tab。(这个问题在每个从 Setting Tab 推送的 ViewController 中都一样)
要求
我不想在 Touch Tab Setting 时将 ViewController 从 ChangePassword ViewController 更改为 Setting ViewController。如何解决?
示例代码:主视图控制器
- (void) addTabbarController
{
// construction List
ConstructionListViewController *constructionListVC = [[ConstructionListViewController alloc] init];
UINavigationController *constructionListNVC = [[UINavigationController alloc] initWithRootViewController:constructionListVC];
// Setting
SettingViewController *settingVC = [[SettingViewController alloc] init];
UINavigationController *settingNVC = [[UINavigationController alloc] initWithRootViewController:settingVC];
// UITabBar Controller
UITabBarController *tabController = [[UITabBarController alloc] init];
tabController.navigationItem.hidesBackButton = YES;
tabController.delegate = self;
tabController.viewControllers = [NSArray arrayWithObjects:constructionListNVC, settingNVC, nil];
tabController.navigationController.navigationBarHidden = YES;
[tabController setSelectedIndex:0];
self.navigationController.navigationBarHidden = YES;
[self.navigationController pushViewController:tabController animated:NO];
}
示例代码:设置 ViewController
-(void) touchOnChangePassword:(QButtonElement *) element
{
ChangePasswordViewController *changePasswordViewController = [[ChangePasswordViewController alloc] init];
[self.navigationController pushViewController: changePasswordViewController animated:YES];
}
// touchOnPasscodeLock Button
-(void) touchOnPasscodeLock:(QButtonElement *) element
{
// go to Passcode Lock Screen
}
-(void) touchOnTermAndCondition:(QButtonElement *) element
{
// go to TermAndCondition Screen
}
-(void) touchOnOpenSourceAttribute:(QButtonElement *) element
{
// go to OpenSourceAttribute Screen
}
示例显示:设置 ViewController
示例显示:更改密码 ViewController
【问题讨论】:
-
使用 tabcontroller.selectedIndex 知道选择了哪个标签
标签: ios objective-c uitabbarcontroller