开发者

iPhone: How do I get the the UINavViewController to not pop the view controller when the user presses the tab that is already selected

I've got a Tab Bar, and each of the tabs' view controllers is a nav controller. If you press on a 开发者_运维百科tab that is already selected, it pops the view controller back. for one the tabs, i want this not to happen. What do i make a delegate of? I tried overriding

-(UIViewController *)popViewControllerAnimated:(BOOL)animated

in the nav controller to return 0, but that doesn't stop it from popping!


user74574 is close, but you shouldn't return nil, you should return NO. Yes, technically they are both the same in term of the bits, bit types have meaning and ignoring that will (depending on the situation) result in warnings and/or bugs that could be detected via static analysis. The could you want to implement in your delegate should be something like this:

- (BOOL)tabBarController:(UITabBarController *)tabBarController_ shouldSelectViewController:(UIViewController *)viewController {
  if (viewController == tabBarController_.selectedViewController) {
    return NO;
  } else {
    return YES;
  }
}


You can accomplish this by subclassing UITabBarController, and setting it as the UITabBarControllerDelegate for itself.

Implement tabBarController:shouldSelectViewController:, testing whether it is selecting the view controller you are concerned about, and if it is already selected. return nil if it satisfies the above.

If you'd like, I can put together some actual code, but this should get you in the right direction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜