iOS 13点击返回按钮闪退问题的解决办法[UINavigationController _popNavigationBar:item:]

Assertion failure in -[UINavigationController _popNavigationBar:item:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3899.13.13/UINavigationController.m:8520

创建UINavigationController的自定义类,然后如下所示添加UINavigationBarDelegate,并将该类分配给UINavigationController

swift

class SJMNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationBar.delegate = self
    }
}

extension SJMNavigationController : UINavigationBarDelegate {
    public func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
        return true
    }
}

oc


@interface SJMNavigationController () 

@end

@implementation SJMNavigationController

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

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

#ifdef __IPHONE_13
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(nonnull UINavigationItem *)item {
    return YES;
}
#endif

你可能感兴趣的:(iOS 13点击返回按钮闪退问题的解决办法[UINavigationController _popNavigationBar:item:])