我的应用程序中有一系列UIViewControllers,这些都是使用UINavigationController呈现的。主ViewController调用pushViewController来访问配置文件ViewController。配置文件屏幕正确地将后退按钮显示到主页。然后,选择配置文件上的按钮将把用户带到DETAIL ViewController。详细信息屏幕正确地将后退按钮显示为配置文件。但当我按下配置文件的后退按钮时,我确实会返回到配置文件屏幕,但该屏幕上的导航栏现在显示的标题主页没有后退按钮。换句话说,iOS8似乎已经弹出了一次ViewController,以便从详细信息返回到个人资料,但不知何故又弹出了两次导航栏项目!
你知道我怎么解决这个问题吗?
发布于 2014-11-27 03:16:13
显然,可以在以下位置找到解决方案概要: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.
}
*/
@endhttps://stackoverflow.com/questions/26413475
复制相似问题