【问题标题】:click navigation tabbaritem popToRootViewController点击导航 tabbaritem popToRootViewController
【发布时间】:2013-09-29 05:59:13
【问题描述】:
  1. 首先我将 TabBarController 直接安装为窗口的根视图控制器,并在 viewControllers 中有一个 NavigationController。
  2. 当应用程序运行时,我将一些新的视图控制器推送到导航堆栈上
  3. 比我点击导航tabbaritem,navigationController poptoRootViewController

如何使第 3 步事件崩溃或阻止它弹出到根目录?

我停止自动弹出到根视图控制器的解决方案:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UITabBarController *tbc = [[UITabBarController alloc]init];

tbc.viewControllers = [NSArray arrayWithObjects:rvc,nil];

tbc.delegate = self;}
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{

if([tabBarController selectedViewController] == viewController)
    return NO;
return YES;}

如果你有其他解决方案,欢迎写下来。

【问题讨论】:

标签: ios objective-c


【解决方案1】:

你在新的 viewController 中实现了 didSelectViewController 方法(推送到新的 viewController)

导入UITabBarControllerDelegate,

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tabBarController.delegate = self;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    [self.tabBarController.navigationController popToRootViewControllerAnimated:YES];
}

【讨论】:

  • 我停止自动弹出到根视图控制器的解决方案:-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ UITabBarController *tbc = [[UITabBarController alloc]init]; tbc.viewControllers = [NSArray arrayWithObjects:rvc,nil]; tbc.delegate = self;} -(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{ if([tabBarController selectedViewController] == viewController) 返回 NO;返回是;}
【解决方案2】:

在标签栏应用程序中尝试此代码

[self.tabBarController.navigationController popToRootViewControllerAnimated:YES];

【讨论】:

  • 对不起,我的意思是当我双击导航的 tabbarItem 时停止 navigationController popToRootViewController。谢谢回答
猜你喜欢
  • 1970-01-01
  • 2017-07-24
  • 2013-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-04
  • 1970-01-01
相关资源
最近更新 更多