[英]UINavigationController Broken in IOS 8?
我的應用程序中有一系列UIViewController,這些是使用UINavigationController呈現的。 HOME ViewController調用pushViewController進入PROFILES ViewController。 PROFILES屏幕將正確顯示返回HOME的返回按鈕。 然后選擇PROFILES上的按鈕會將用戶帶到DETAIL ViewController。 詳細信息屏幕正確顯示PROFILES的后退按鈕。 但是,當我將“后退”按鈕按到“個人檔案”時,的確確實返回了“個人檔案”屏幕,但是該屏幕上的導航欄現在顯示標題HOME,沒有后退按鈕。 換句話說,IOS 8似乎已經彈出ViewController一次,從DETAIL返回到PROFILES,但是不知何故又兩次彈出了導航欄項!
知道我該如何解決嗎?
顯然,可以在此處找到解決方案概述: 具有MonoTouch的UINavigationController和UINavigationBarDelegate.ShouldPopItem()
在我的解決方案中,我只是將所有視圖控制器都擴展了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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.