开发者

application terminating due to an uncaught exception , when using :(id) sender on an IBAction

开发者 https://www.devze.com 2023-02-16 21:06 出处:网络
I have an application that is using a modal view that has some buttons on it. When I press a button I am calling the following function:

I have an application that is using a modal view that has some buttons on it. When I press a button I am calling the following function:

-(IBAction)iconWasSelected:(id) sender
{
    NSLog(@"icon button was pressed");
    [self dismissModalViewControllerAnimated:YES];
}

If I remove the :(id) sender; it works just fine, but I am trying to get the object that is triggering the function.

This is the error its "vomiting":

2011-03-11 22:59:55.793 app[14107:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IconPickerViewController iconWasSelected]: unrecognized selector sent to instance 0x800bbf0'
*** Call stack at first throw:
(
        0   CoreFoundation                      0x01629be9 __exceptionPreprocess + 185
        1   libobjc.A.dylib                     0x0177e5c2 objc_exception_throw + 47
        2   CoreFoundation                      0x0162b6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
        3   CoreFoundation                      0x0159b366 ___forwarding___ + 966
        4   CoreFoundation                      0x0159af22 _CF_forwarding_prep_0 + 50
        5   UIKit                               0x0053da6e -[UIApplication sendAction:to:from:forEvent:] + 119
        6   UIKit                               0x005cc1b5 -[UIControl sendAction:to:forEvent:] + 67
        7   UIKit                               0x005ce647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
        8   UIKit                               0x005cd1f4 -[UIControl touchesEnded:withEvent:] + 458
        9   UIKit                               0x005620d1 -[UIWindow _sendTouchesForEvent:] + 567
        10  UIKit                               0x0054337a -[UIApplication sendEvent:] + 447
        11  UIKit                               0x00548732 _UIApplicationHandleEvent + 7576
        12  GraphicsServices                    0x01ce4a36 PurpleEventCallback + 1550
        13  CoreFoundation                      0x0160b064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
        14  CoreFoundation                      0x0156b6f7 __CFRunLoopDoSource1 + 215
        15  开发者_运维百科CoreFoundation                      0x01568983 __CFRunLoopRun + 979
        16  CoreFoundation                      0x01568240 CFRunLoopRunSpecific + 208
        17  CoreFoundation                      0x01568161 CFRunLoopRunInMode + 97
        18  GraphicsServices                    0x01ce3268 GSEventRunModal + 217
        19  GraphicsServices                    0x01ce332d GSEventRun + 115
        20  UIKit                               0x0054c42e UIApplicationMain + 1160
        21  naggy                               0x00002298 main + 102
        22  naggy                               0x00002229 start + 53
)
terminate called after throwing an instance of 'NSException'

Any clues?!! Help and Thanks!!


If you're calling the method programmatically, then make sure you set the action correctly. For example, this will work when (id)sender is present:

UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"CLICK ME" 
                                                              style:UIBarButtonItemStyleBordered 
                                                             target:self 
                                                             action:@selector(iconWasSelected:)];

and this will work when (id)sender is not present:

UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"CLICK ME" 
                                                              style:UIBarButtonItemStyleBordered 
                                                             target:self 
                                                             action:@selector(iconWasSelected)];

Notice the only difference in the code is the colon!

0

精彩评论

暂无评论...
验证码 换一张
取 消