Search code examples
swiftuinavigationcontrolleruibuttonxibxcode7.3

Abnormal behaviour of uinavigationcontroller Clicking at UIButton throws exception


I been using objective C 5years back and now start working in Swift. I am facing this abnormal behaviour, google a lot but still not getting the solution, I am posting here so that it might happened with some else and might help me to get rid of this issue!

Scenario is : I am not using storyboard instead xibs. In AppDelegate (roorviewcontroller is navigationcotroller) ->mainview controller is loading successfully -> 2nd view controller is loading successfully from main view controller as well but from 2ndviewcontroller: I am not able to push/pop (clicking on button throwing falling exception. You can test this scenario at your end, it's not like i am changing text of ibaction or iboutlet etc.

In 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()

In ViewControllers:

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

}

Stack Trace:

 -[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

Solution

  • We have figure this out and it may help some one to save his time, It is working now "By replacing UIViewController with DViewController!