【问题标题】:How to check selected Tab Bar如何检查选定的标签栏
【发布时间】: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

【问题讨论】:

标签: ios objective-c uitabbarcontroller


【解决方案1】:

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

【讨论】:

  • 我使用-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 来检查选项卡。它总是访问这个委托方法。我在委托中有一些方法使用。我的问题可以使用这个委托吗?如何解决?
  • didSelectViewController 为时已晚;视图控制器已被选中。为什么不使用shouldSelect?这就是它的用途。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-26
  • 1970-01-01
  • 2012-10-05
  • 2011-06-10
  • 1970-01-01
  • 2017-04-08
相关资源
最近更新 更多