Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARC and UIAlertView: unrecognized selector sent to instance

Here is how I show UIAlertView and the delegate clickedButtonAtIndex -

UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle: @"title"
                               message: @"message"
                              delegate: self
                     cancelButtonTitle: @"Cancel"
                     otherButtonTitles: @"Continue", nil];

    [alert show];


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    //something
}

This piece of code works perfectly without ARC. But with ARC it throws this error - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType alertView:clickedButtonAtIndex:]: unrecognized selector sent to instance 0x859d790'

Any ideas on why the delegate is throwing this error?

like image 323
arank Avatar asked Dec 15 '11 02:12

arank


1 Answers

Your delegate has been dealloc'd. Double-check your code to make sure the object that is showing the alert and setting itself as the delegate is being retained somehow (ie: something in your app has a strong reference to it).

like image 147
Nicholas Hart Avatar answered Nov 08 '22 16:11

Nicholas Hart