uinavigationcontroller 异常行为点击 UIButton 抛出异常

Abnormal behaviour of uinavigationcontroller Clicking at UIButton throws exception

5 年前我一直在使用 objective C,现在开始使用 Swift。我遇到了这种异常行为,google 很多,但仍然没有得到解决方案,我在这里发帖,这样它可能会发生在其他人身上,并可能帮助我摆脱这个问题!

场景是: 我没有使用情节提要而不是 xibs。在 AppDelegate 中(roorviewcontroller 是 navigationcotroller)->mainview 控制器加载成功->第二个视图控制器也从主视图控制器成功加载,但是从 2ndviewcontroller 加载:我无法 push/pop(单击按钮抛出异常。你可以在你这边测试这个场景,这不像我在改变 ibaction 或 iboutlet 等的文本。

在 AppDelegate 中:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
    window?.backgroundColor = UIColor.whiteColor()
    let mainViewController = MainViewController()
    let navController = UINavigationController(rootViewController: mainViewController)

    window!.rootViewController = navController
    window!.makeKeyAndVisible()

在视图控制器中:

@IBAction func nextScreen()
{
    let loginViewController = UIViewController(nibName: "DViewController", bundle: nil)
    navigationController?.pushViewController(loginViewController, animated: true, completion: nil)

}

堆栈跟踪:

 -[UIViewController getTaf]: unrecognized selector sent to instance 0x7d961f10
 2017-01-07 20:15:00.125 January7[5083:187391] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController getTaf]: unrecognized selector sent to instance 0x7d961f10'
 *** First throw call stack:
(
0   CoreFoundation                      0x002c2494 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x01fd9e02 objc_exception_throw + 50
2   CoreFoundation                      0x002cc253 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3   CoreFoundation                      0x0020189d ___forwarding___ + 1037
4   CoreFoundation                      0x0020146e _CF_forwarding_prep_0 + 14
5   libobjc.A.dylib                     0x01fee0b5 -[NSObject performSelector:withObject:withObject:] + 84
6   UIKit                               0x00ab4e38 -[UIApplication sendAction:to:from:forEvent:] + 118
7   UIKit                               0x00ab4db7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
8   UIKit                               0x00c58f3b -[UIControl sendAction:to:forEvent:] + 79
9   UIKit                               0x00c592d4 -[UIControl _sendActionsForEvents:withEvent:] + 433
10  UIKit                               0x00c582c1 -[UIControl touchesEnded:withEvent:] + 714
11  UIKit                               0x00b3552e -[UIWindow _sendTouchesForEvent:] + 1095
12  UIKit                               0x00b365cc -[UIWindow sendEvent:] + 1159
13  UIKit                               0x00ad7be8 -[UIApplication sendEvent:] + 266
14  UIKit                               0x00aac769 _UIApplicationHandleEventQueue + 7795
15  CoreFoundation                      0x001d4e5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16  CoreFoundation                      0x001caaeb __CFRunLoopDoSources0 + 523
17  CoreFoundation                      0x001c9f08 __CFRunLoopRun + 1032
18  CoreFoundation                      0x001c9846 CFRunLoopRunSpecific + 470
19  CoreFoundation                      0x001c965b CFRunLoopRunInMode + 123
20  GraphicsServices                    0x047d9664 GSEventRunModal + 192
21  GraphicsServices                    0x047d94a1 GSEventRun + 104
22  UIKit                               0x00ab2eb9 UIApplicationMain + 160
23  January7                            0x000cf781 main + 145
24  libdyld.dylib                       0x029f7a25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我们已经解决了这个问题,它可能会帮助一些人节省时间,它现在正在工作“通过用 DViewController 替换 UIViewController!