首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UINavigationController在iOS8中崩溃了吗?

UINavigationController在iOS8中崩溃了吗?
EN

Stack Overflow用户
提问于 2014-10-17 04:37:01
回答 1查看 262关注 0票数 0

我的应用程序中有一系列UIViewControllers,这些都是使用UINavigationController呈现的。主ViewController调用pushViewController来访问配置文件ViewController。配置文件屏幕正确地将后退按钮显示到主页。然后,选择配置文件上的按钮将把用户带到DETAIL ViewController。详细信息屏幕正确地将后退按钮显示为配置文件。但当我按下配置文件的后退按钮时,我确实会返回到配置文件屏幕,但该屏幕上的导航栏现在显示的标题主页没有后退按钮。换句话说,iOS8似乎已经弹出了一次ViewController,以便从详细信息返回到个人资料,但不知何故又弹出了两次导航栏项目!

你知道我怎么解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2014-11-27 03:16:13

显然,可以在以下位置找到解决方案概要:UINavigationController and UINavigationBarDelegate.ShouldPopItem() with MonoTouch

在我的解决方案中,我只是让我的所有视图控制器都扩展了CustomUINavigationController,如下所示:

代码语言:javascript
运行
复制
#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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26413475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档