uinavigationcontroller的异常行为单击UIButton会抛出异常

时间:2017-01-07 16:16:03

标签: swift uinavigationcontroller uibutton xib xcode7.3

我一直在使用目标C 5年,现在开始在Swift工作。我正面临这种异常行为,谷歌很多,但仍然没有得到解决方案,我发布在这里,以便它可能发生在其他一些,可能会帮助我摆脱这个问题!

场景是: 我不使用故事板而不是xibs。在AppDelegate(roorviewcontroller是navigationcotroller) - >主视图控制器正在成功加载 - >第二个视图控制器也从主视图控制器成功加载,但是来自2ndviewcontroller:我无法按下/弹出(点击按钮抛出异常。你可以在最后测试这个场景,这不像我正在改变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()

在ViewControllers中:

@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

1 个答案:

答案 0 :(得分:0)

我们已经弄明白这可能有助于某人节省他的时间,它现在正在工作“通过用DViewController替换UIViewController!

相关问题