简体   繁体   English

NSInvalidArgumentException || 无法识别的选择器已发送到实例

[英]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. 我猜GroupsGroup对象的集合。 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.

相关问题 'NSInvalidArgumentException'/'-[AppDelegate fieldChanged:]:无法识别的选择器已发送到实例 - 'NSInvalidArgumentException' / '-[AppDelegate fieldChanged:]: unrecognized selector sent to instance CoreData和NSInvalidArgumentException无法识别的选择器发送到实例 - CoreData and NSInvalidArgumentException unrecognized selector sent to instance 异常'NSInvalidArgumentException',原因:'-[AnnotationView setCoordinate:]:无法识别的选择器已发送到实例 - exception 'NSInvalidArgumentException', reason: '-[AnnotationView setCoordinate:]: unrecognized selector sent to instance 'NSInvalidArgumentException':无法识别的选择器发送到实例0x8d25aa0' - 'NSInvalidArgumentException': unrecognized selector sent to instance 0x8d25aa0' 'NSInvalidArgumentException'-[UIViewController tableView:numberOfRowsInSection:]-无法识别的选择器已发送到实例 - 'NSInvalidArgumentException' - [UIViewController tableView:numberOfRowsInSection:] - unrecognized selector sent to instance NSInvalidArgumentException-无法识别的选择器已发送到实例 - NSInvalidArgumentException - Unrecognised Selector Sent to instance 无法识别的选择器发送到实例 - Unrecognized selector sent to instance 无法识别的选择器已发送到实例 - unrecognized selector sent to instance 无法识别的选择器发送到实例 - unrecognized selector sent to instance 无法识别的选择器发送到实例 - unrecognized selector sent to instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM