[英]NSInvalidArgumentException || Unrecognized selector sent to instance
I have a tableView and I create a Button on one cell. 我有一个tableView,并且在一个单元格上创建了一个Button。
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' "
“由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[Group deleteGroup:]:无法识别的选择器已发送到实例0x5a8afc0'”
And that is my deleteGroupButtonClicked method 那就是我的deleteGroupButtonClicked方法
- (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, 您的deleteGroupButtonClicked:方法中有些奇怪的地方,
You have a object of class Groups
but you are alloc'ing an object of class Group
. 您有一个
Groups
类的对象,但是正在分配Group
类的对象。 I am guessing Groups
is a collection of Group
objects. 我猜
Groups
是Group
对象的集合。 In which case a deleteGroup:
method would only exist in the Groups
class. 在这种情况下,
deleteGroup:
方法将仅存在于Groups
类中。
Just replace your deleteGroupButtonClicked method with the following: 只需将您的deleteGroupButtonClicked方法替换为以下内容:
- (void) deleteGroupButtonClicked: (id) sender
{
Groups *tmpGroups = [[Groups alloc] init];
NSInteger tmp = appDelegate.selectedGroupId;
[tmpGroups deleteGroup:tmp];
[tmpGroups release];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.