Amit Battan
Amit Battan

Reputation: 3018

Application crash on UIButton click : iphone

I have a View base iphone application
I add a NSObject class AddNewContact and take its object in IB

AddNewContact.h

#import <Foundation/Foundation.h>

@interface AddNewContact : NSObject {
}
-(IBAction)abc:(id)sender;
@end

AddNewContact.m

#import "AddNewContact.h"

@implementation AddNewContact

-(IBAction)abc:(id)sender{
    NSLog(@"this is test");
}
@end

I bind a UIButton action to abc: on clicking the button application crashes, even NSLog is also not logged
but if I bind the button action to other classes function then it working ok

Crash Log

2011-06-08 15:40:30.368 myApp[5466:207] -[NSCFString abc:]: unrecognized selector sent to instance 0x6b7b1c0
2011-06-08 15:40:30.416 myApp[5466:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString abc:]: unrecognized selector sent to instance 0x6b7b1c0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02ad9b99 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x02c2940e objc_exception_throw + 47
    2   CoreFoundation                      0x02adb6ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x02a4b2b6 ___forwarding___ + 966
    4   CoreFoundation                      0x02a4ae72 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x0039e7f8 -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x00429de0 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x0042c262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x0042ae0f -[UIControl touchesEnded:withEvent:] + 458
    9   UIKit                               0x003c23d0 -[UIWindow _sendTouchesForEvent:] + 567
    10  UIKit                               0x003a3cb4 -[UIApplication sendEvent:] + 447
    11  UIKit                               0x003a89bf _UIApplicationHandleEvent + 7672
    12  GraphicsServices                    0x0306a822 PurpleEventCallback + 1550
    13  CoreFoundation                      0x02abaff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x02a1b807 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x02a18a93 __CFRunLoopRun + 979
    16  CoreFoundation                      0x02a18350 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x02a18271 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x0306900c GSEventRunModal + 217
    19  GraphicsServices                    0x030690d1 GSEventRun + 115
    20  UIKit                               0x003acaf2 UIApplicationMain + 1160
    21  myApp                           0x00001fa4 main + 102
    22  myApp                           0x00001f35 start + 53
)
terminate called after throwing an instance of 'NSException'

Can anybody tell me where I am wrong

Thanks
Amit Battan

Upvotes: 0

Views: 2333

Answers (1)

Simon Lee
Simon Lee

Reputation: 22334

You will be releasing your AddNewContact view controller, the view is still in the superview but the viewController is released, the button tries to call 'abc' on AddNewContact controller which no longer exists...

Upvotes: 9

Related Questions