[英]Unrecognized selector sent to instance
Anyone know why I am getting this error? 任何人都知道我为什么会收到此错误?
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomRaisedTabViewController cancel:]: unrecognized selector sent to instance 0x4d321e0'
This is the code where it is failing. 这是它失败的代码。 This is in my CustomTabViewController
. 这是在我的CustomTabViewController
。 The error is happening when I click my "Cancel" button. 单击“取消”按钮时发生错误。
-(IBAction)showPostModalViewController {
PostActionModalViewController *addController = [[PostActionModalViewController alloc]
initWithNibName:@"PostActionModalView" bundle:nil];
// Configure the PostAddViewController. In this case, it reports any
// changes to a custom delegate object.
addController.delegate = self;
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
UIBarButtonItem *cancelButton =
[[UIBarButtonItem alloc] initWithTitle: @"Cancel"
style: UIBarButtonItemStylePlain
target: self
action: @selector(cancel:)];
addController.navigationItem.rightBarButtonItem = cancelButton;
[cancelButton release];
//[self presentModalViewController:addController animated:true];
[navigationController release];
[addController release];
}
-(IBAction)cancel {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
Because the cancel:
method is not cancel
which is what you've defined. 因为cancel:
方法不是cancel
,这是你定义的。
Change your cancel
action to look like this: 将cancel
操作更改为如下所示:
- (IBAction)cancel:(id)sender {
...
}
action: @selector(cancel:)
For the action selector which takes parameter! 对于带参数的动作选择器! cancel: that means which will take another parameter. 取消:这意味着哪个将采用另一个参数。
change your method to 将你的方法改为
-(IBAction)cancel:(id)sender{
// Do wat you want
}
or
-(IBAction)cancel:(UIButton *)btnSender{
/// Do what you want
}
you have to modify the cancel method signature in 你必须修改取消方法签名
-(IBAction)cancel:(id)sender
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
when you added the action to your cancelButton (during initialization) you specified the "cancel:" selector, this means that it will be called a method having one parameter (the sender button) 当您将操作添加到cancelButton时(在初始化期间),您指定了“cancel:”选择器,这意味着它将被称为具有一个参数的方法(发送者按钮)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.