Xcode 在iOS 13上按下新视图后,“后退”按钮崩溃

Xcode 在iOS 13上按下新视图后,“后退”按钮崩溃,xcode,ios13,xcode11,Xcode,Ios13,Xcode11,我有一个应用程序在iOS 12上运行得非常完美。我想在iOS 13,XCode 11上进行测试。我使用情节提要导航序列将一个视图控制器推到另一个视图控制器。当我按下第二页上的后退按钮(默认后退按钮)时,应用程序崩溃并产生下面的错误。它发生在每个导航页面,甚至是空视图中 2019-08-28 14:10:48.632540+0300 App Name[28453:400531] *** Assertion failure in -[UINavigationController _popNaviga

我有一个应用程序在iOS 12上运行得非常完美。我想在iOS 13,XCode 11上进行测试。我使用情节提要导航序列将一个视图控制器推到另一个视图控制器。当我按下第二页上的后退按钮(默认后退按钮)时,应用程序崩溃并产生下面的错误。它发生在每个导航页面,甚至是空视图中

2019-08-28 14:10:48.632540+0300 App Name[28453:400531] *** Assertion failure in -[UINavigationController _popNavigationBar:item:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3899.13.11/UINavigationController.m:8520
2019-08-28 14:10:48.642352+0300 App Name[28453:400531] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Override of -navigationBar:shouldPopItem: returned YES after manually popping a view controller (navigationController=<UINavigationController: 0x7fa22f0de000>)'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23afdbde __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff5015cb20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23afd958 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff255506f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   UIKitCore                           0x00007fff46812310 -[UINavigationController _popNavigationBar:item:] + 379
    5   UIKitCore                           0x00007fff46592209 -[UINavigationBar _sendNavigationPopForBackBarButtonItem:] + 277
    6   UIKitCore                           0x00007fff465bf771 -[_UINavigationBarContentView __backButtonAction:] + 58
    7   UIKitCore                           0x00007fff46f0abc1 -[UIApplication sendAction:to:from:forEvent:] + 83
    8   UIKitCore                           0x00007fff468fc3e5 -[UIControl sendAction:to:forEvent:] + 223
    9   UIKitCore                           0x00007fff468fc72f -[UIControl _sendActionsForEvents:withEvent:] + 398
    10  UIKitCore                           0x00007fff468fc892 -[UIControl _sendActionsForEvents:withEvent:] + 753
    11  UIKitCore                           0x00007fff468fb68e -[UIControl touchesEnded:withEvent:] + 481
    12  UIKitCore                           0x00007fff46f450c7 -[UIWindow _sendTouchesForEvent:] + 2604
    13  UIKitCore                           0x00007fff46f469ce -[UIWindow sendEvent:] + 4596
    14  UIKitCore                           0x00007fff46f2204f -[UIApplication sendEvent:] + 356
    15  UIKitCore                           0x00007fff46fa18c0 __dispatchPreprocessedEventFromEventQueue + 6847
    16  UIKitCore                           0x00007fff46fa4386 __handleEventQueueInternal + 5980
    17  CoreFoundation                      0x00007fff23a60ac1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    18  CoreFoundation                      0x00007fff23a609ec __CFRunLoopDoSource0 + 76
    19  CoreFoundation                      0x00007fff23a601c4 __CFRunLoopDoSources0 + 180
    20  CoreFoundation                      0x00007fff23a5aecf __CFRunLoopRun + 1263
    21  CoreFoundation                      0x00007fff23a5a6b6 CFRunLoopRunSpecific + 438
    22  GraphicsServices                    0x00007fff38016bb0 GSEventRunModal + 65
    23  UIKitCore                           0x00007fff46f0990f UIApplicationMain + 1621
    24  App Name                           0x000000010691b810 main + 112
    25  libdyld.dylib                       0x00007fff50fe1cf5 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
2019-08-28 14:10:48.632540+0300应用程序名[28453:400531]***-[UINavigationController\u popNavigationBar:item:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore\u Sim/UIKit-3899.13.11/UINavigationController.m:8520中的断言失败
2019-08-28 14:10:48.642352+0300应用程序名称[28453:400531]***由于未捕获的异常“nSinternalinconsistenceexception”而终止应用程序,原因:“覆盖-navigationBar:ShouldPopiItem:在手动弹出视图控制器(navigationController=)后返回YES”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x00007FFF23AFDBE例外预处理+350
1 libobjc.A.dylib 0x00007fff5015cb20 objc_异常_抛出+48
2 CoreFoundation 0x00007fff23afd958+[N异常提升:格式:参数:][88
3基金会0x000 7FFF255506F5- [ NSRealStutsHuffer-HuffLeuluIn方法:对象:文件:文件号:描述:] + 191
4 UIKitCore 0x00007fff46812310-[UINavigationController\u popNavigationBar:项::+379
5 UIKitCore 0x00007FFF4659209-[UINavigationBar _sendNavigationPopforBackbarButtonim:+277
6 UIKitCore 0x00007fff465bf771-[\u UINavigationBarContentView\u backButtonAction:][58
7 UIKitCore 0x00007fff46f0abc1-[UIApplication sendAction:to:from:forEvent:+83
8 UIKitCore 0x00007fff468fc3e5-[UIControl发送操作:发送到:forEvent:+223
9 UIKitCore 0x00007fff468fc72f-[UIControl\u发送操作预防:带事件:][398
10 UIKitCore 0x00007fff468fc892-[UIControl\u发送操作预防:withEvent:+753
11 UIKitCore 0x00007fff468fb68e-[UIControl触摸已选择:带事件:][481
12 UIKitCore 0x00007fff46f450c7-[UIWindow\u sendTouchesForEvent:+2604
13 UIKitCore 0x00007fff46f469ce-[UIWindow sendEvent::+4596
14 UIKitCore 0x00007fff46f2204f-[UIApplication sendEvent:][356
15 UIKitCore 0x00007fff46fa18c0 uuu调度预处理版本RomeventQueue+6847
16 UIKitCore 0x00007fff46fa4386 _uhandleeventqueueinternal+5980
17 CoreFoundation 0x00007fff23a60ac1\uuuu CFRUNLOOP\u正在调用\uu OUT\u以执行\uuu功能\uuuu+17
18 CoreFoundation 0x00007fff23a609ec__CFRunLoopDoSource0+76
19 CoreFoundation 0x00007fff23a601c4__CFRunLoopDoSources0+180
20 CoreFoundation 0x00007fff23a5aecf__CFRunLoopRun+1263
21 CoreFoundation 0x00007fff23a5a6b6 CFRunLoopRunSpecific+438
22图形服务0x00007fff38016bb0 GSEventRunModal+65
23 UIKitCore 0x00007fff46f0990f UIApplicationMain+1621
24应用程序名称0x000000010691b810 main+112
25 libdyld.dylib 0x00007fff50fe1cf5开始+1
26???0x0000000000000001 0x0+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)

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

 class MyNavigationController: UINavigationController {

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

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

我不知道这对你来说是否仍然是一个问题,但我有一个类似的问题(实际上我的问题是它在ios13上工作得很好,但在ios12上“后退”按钮不起作用)

错误告诉您不能手动弹出viewcontroller,然后返回true(即,您应该弹出viewcontroller),因此如果手动弹出,则需要返回false

override public func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
        popViewController(animated: true)
        return false
    }

您是否覆盖了UINavigationBar的
shouldPopItem
委托?我刚刚覆盖了,并添加了UINavigationControllerDelegate、UINavigationBarDelegate。但是shouldPopItem没有被调用。嘿,你找到解决方案了吗?现在它没有崩溃。但不弹出viewcontroller