0

我在我的应用程序中有一系列UIViewControllers,并且这些都是使用UINavigationController呈现的。 HOME ViewController调用pushViewController进入PROFILES ViewController。 PROFILES屏幕正确显示返回按钮到HOME。然后在PROFILES上选择一个按钮将使用户进入DETAIL ViewController。 DETAIL屏幕正确显示PROFILES的后退按钮。但是当我将后退按钮按下到PROFILES时,我确实回到PROFILES屏幕,但屏幕上的导航栏现在显示标题HOME,没有后退按钮。换句话说,看起来IOS8已经弹出ViewController一次从细节返回到PROFILES,但以某种方式弹出导航栏项目两次!UINavigationController在IOS 8中损坏?

任何想法如何解决这个问题?

+0

你可能要包括哪些你用来推入导航堆栈的机制。你使用故事板吗?你在使用segues吗?你使用pushViewController:?另外,你的日志中是否提到了有关腐败导航堆栈的任何内容? – atreat 2014-10-16 20:39:38

+0

我只是使用旧的标准pushViewController。我不使用storyboard或segues。这是非常基本的IOS编码,可以在旧版本的IOS和XCode中正常工作,但似乎在使用XCode 6的IOS8中被破坏。 – Marc 2014-10-16 21:09:15

+0

您是否得到了解决方案?我有同样的问题 – 2014-11-26 09:02:33

回答

0

显然,解决方案的轮廓可以在这里找到: UINavigationController and UINavigationBarDelegate.ShouldPopItem() with MonoTouch

在我的解决方案,我只是有我所有的视图控制器扩展CustomUINavigationController,它看起来像这样:

#import "CustomUINavigationController.h" 
#import "IOSVersion.h" 

@interface CustomUINavigationController() 

@end 

@implementation CustomUINavigationController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    self.delegate=self; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

// 
// The following two methods are the key to overriding the buggy behavior in IOS 8 
// The first method is from here: 
// https://stackoverflow.com/questions/6413595/uinavigationcontroller-and-uinavigationbardelegate-shouldpopitem-with-monotouc 
// 
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item { 
    NSLog(@"Inside shouldPopItem"); 
    if (regularPop) { 
     NSLog(@"regularPop is TRUE"); 
    } else { 
     NSLog(@"regularPop is FALSE"); 
    } 
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { 
     if (regularPop) { 
      regularPop = FALSE; 
      return YES; 
     } 

     regularPop = TRUE; 
     [self popViewControllerAnimated:YES]; 
     return NO; 
    } else { 
     return [super navigationBar:navigationBar shouldPopItem:item]; 
    } 
} 

- (UIViewController *)popViewControllerAnimated:(BOOL)animated 
{ 
    NSLog(@"Inside popViewControllerAnimated"); 
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { 
     NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.viewControllers]; 
     int cnt=(int)[viewControllers count]; 
     NSLog(@"Inside popViewControllerAnimated, cnt is %d",cnt); 
     UIViewController *vc=[viewControllers objectAtIndex:cnt-2]; 
     if (regularPop) self.desiredVC=vc; 
     [self popToViewController:vc animated:animated]; 
     return vc; 
    } else { 
     return [super popViewControllerAnimated:animated]; 
    } 

} 

- (UIViewController *)manualpopViewControllerAnimated:(BOOL)animated { 
    NSLog(@"Inside manualpopViewControllerAnimated"); 
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { 
     regularPop=TRUE; 
     return [self popViewControllerAnimated:animated]; 
    } else { 
     return [super popViewControllerAnimated:animated]; 
    } 
} 

- (void)navigationController:(UINavigationController *)navigationController 
    didShowViewController:(UIViewController *)viewController 
       animated:(BOOL)animated { 
    NSLog(@"Inside didShowViewController"); 
    if (viewController==self.desiredVC) { 
     NSLog(@"Inside didShowViewController, found desiredVC"); 
     regularPop = FALSE; 
    } 
} 

/* 
#pragma mark - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 
} 
*/ 

@end 
+0

Hi Marc,什么是“IOSVersion.h”?那是你的另一个自定义类吗? – Sevren 2014-12-11 19:29:37

+0

是的,这只是一个我使用的文件,它有像SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@“8.0”)这样的宏。你当然可以从名字中推断出他们做了什么。例如:#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch]!= NSOrderedDescending) – Marc 2014-12-12 00:02:53