我有一个可以在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)
答案 0 :(得分:0)
创建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
}
}
答案 1 :(得分:0)
我不知道这是否对您来说仍然是一个问题,但是我有类似的事情(实际上我的问题是它在ios13上可以正常运行,但在ios12上,后退按钮不起作用)。
该错误告诉您不能手动弹出viewcontroller,然后返回true(即,应该弹出viewController),因此如果手动弹出,则需要返回false
override public func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
popViewController(animated: true)
return false
}