Ios 如何检查选定的选项卡栏

Ios 如何检查选定的选项卡栏,ios,objective-c,uitabbarcontroller,Ios,Objective C,Uitabbarcontroller,在我的项目中,我通过编程方式创建TabBarController 有2个选项卡栏。(构造列表选项卡和设置选项卡) 在设置选项卡中,当按下下一个viewController(例如更改密码)时,它工作正常 但在ChangePassword ViewController中,当触按Tab时,设置视图将更改为设置选项卡。(在每个从设置选项卡推送的ViewController中,此问题相同) 要求 触摸选项卡设置时,我不想将ViewController从ChangePassword ViewControll

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

有2个选项卡栏。(构造列表选项卡和设置选项卡)

在设置选项卡中,当按下下一个viewController(例如更改密码)时,它工作正常

但在ChangePassword ViewController中,当触按Tab时,设置视图将更改为设置选项卡。(在每个从设置选项卡推送的ViewController中,此问题相同)

要求

触摸选项卡设置时,我不想将ViewController从ChangePassword ViewController更改为Setting 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];
}
-(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

- (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];
}
-(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

- (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];
}
-(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

- (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];
}
-(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
}

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

我使用
-(void)tabbar控制器:(UITabBarController*)tabbar控制器didSelectViewController:(UIViewController*)viewController
来检查选项卡的显示时间。总是可以访问此委托方法。我在委托中使用了一些方法。我的问题可以使用此代理吗?如何解决?
didSelectViewController
为时已晚;已选择视图控制器。为什么不使用
应选择
?这就是它的用途。使用tabcontroller.selectedIndex了解选择了哪个选项卡这可能会对您有所帮助