如何检查选定的标签栏

时间:2014-07-24 03:07:43

标签: ios objective-c uitabbarcontroller

在我的项目中,我通过编程方式创建了TabBarController。

有2个标签栏。(构造列表标签和设置标签)

在推送到下一个viewController(例如ChangePassword)时的设置选项卡中,它工作正常。

但是在ChangePassword ViewController中触摸选项卡设置视图将更改为设置选项卡。(从设置选项卡中推送的每个ViewController都有同样的问题)

要求

触摸标签设置时,我不想将ViewController从ChangePassword ViewController更改为设置ViewController。如何解决?

示例代码:主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

enter image description here

示例显示:更改密码ViewController

enter image description here

1 个答案:

答案 0 :(得分:0)

为什么不使用UITabBarControllerDelegate方法?您已设置委托但我没有看到您实现委托方法。它们可以帮助您有选择地阻止更改选项卡视图。