DrRocket
DrRocket

Reputation: 235

App crashes when I pop a view from NavigationController using a UIButton

I'm pushing a simple view onto a NavigationController. The view loads fine, and when I use the built-in back button, it is properly popped.

However, when I try and pop the view with my own UIButton within the view, I get a crash.

This is the action run by my UIButton:

-(IBAction)iAgreePressed {

[[self navigationController] popViewControllerAnimated:YES];}

Am I missing something obvious here?

This is the error coming back in the console:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LegalAgreementController iAgreePressed:]: unrecognized selector sent to instance 0x6169190'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0283ab99 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0298a40e objc_exception_throw + 47
    2   CoreFoundation                      0x0283c6ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x027ac2b6 ___forwarding___ + 966
    4   CoreFoundation                      0x027abe72 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x002d67f8 -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x00361de0 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00364262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x00362e0f -[UIControl touchesEnded:withEvent:] + 458
    9   UIKit                               0x002fa3d0 -[UIWindow _sendTouchesForEvent:] + 567
    10  UIKit                               0x002dbcb4 -[UIApplication sendEvent:] + 447
    11  UIKit                               0x002e09bf _UIApplicationHandleEvent + 7672
    12  GraphicsServices                    0x02f57822 PurpleEventCallback + 1550
    13  CoreFoundation                      0x0281bff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x0277c807 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x02779a93 __CFRunLoopRun + 979
    16  CoreFoundation                      0x02779350 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x02779271 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x02f5600c GSEventRunModal + 217
    19  GraphicsServices                    0x02f560d1 GSEventRun + 115
    20  UIKit                               0x002e4af2 UIApplicationMain + 1160
    21  WeiglWorksMobileCommander           0x00001fa2 main + 84
    22  WeiglWorksMobileCommander           0x00001f45 start + 53
    23  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'

Thank you for your time!

Upvotes: 0

Views: 250

Answers (1)

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

Method signatures don't match. The button is sending

-[LegalAgreementController iAgreePressed:]

but you defined

-[LegalAgreementController iAgreePressed] //(note one arg versus no arg)

IBActions should be defined as:

- (IBAction) someMethod:(id)sender

You don't strictly have to include that arg, but you want to for consistency.

Upvotes: 1

Related Questions