简体   繁体   中英

NSInvalidArgumentException || Unrecognized selector sent to instance

I have a tableView and I create a Button on one cell.

UIButton *deleteGroupButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteGroupButton setFrame:CGRectMake(218, 12, 40, 60)];
    [deleteGroupButton addTarget:self action:@selector(deleteGroupButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

When I click to button, an Exception occur with that message:

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Group deleteGroup:]: unrecognized selector sent to instance 0x5a8afc0' "

And that is my deleteGroupButtonClicked method

- (void) deleteGroupButtonClicked: (id) sender {    

    Groups *tmpGroups = [[Group alloc] init];
    NSInteger tmp = appDelegate.selectedGroupId;
    [tmpGroups deleteGroup:tmp];
    [tmpGroups release];
}

You have something slightly odd in your deleteGroupButtonClicked: method,

You have a object of class Groups but you are alloc'ing an object of class Group . I am guessing Groups is a collection of Group objects. In which case a deleteGroup: method would only exist in the Groups class.

Just replace your deleteGroupButtonClicked method with the following:

- (void) deleteGroupButtonClicked: (id) sender 
{    

Groups *tmpGroups = [[Groups alloc] init];
NSInteger tmp = appDelegate.selectedGroupId;
[tmpGroups deleteGroup:tmp];
[tmpGroups release];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM