将 UIButton 添加到 UITextField 导致发送无法识别的选择器
我的错误是:
2011-03-12 20:48:33.861 SmarTrek[22040:207] -[RouteViewController selectFavorite]: unrecognized selector sent to instance 0x5b154a0
2011-03-12 20:48:33.863 SmarTrek[22040:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException'
代码是:
- (void)viewDidLoad
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateHighlighted];
button.bounds = CGRectMake(0, 0, 0, 29);
button.imageEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 0);
[button addTarget:self action:@selector(selectFavorite) forControlEvents:UIControlEventTouchUpInside];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateHighlighted];
button1.bounds = CGRectMake(0, 0, 0, 29);
button1.imageEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 0);
[button1 addTarget:self action:@selector(selectFavorite) forControlEvents:UIControlEventTouchUpInside];
origin.rightView = button;
destination.rightView = button1;
origin.rightViewMode = UITextFieldViewModeAlways;
destination.rightViewMode = UITextFieldViewModeAlways;
self.navigationItem.title = @"Where to go?";
//self.navigationItem.leftBarButtonItem;
//self.navigationItem.rightBarButtonItem;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (IBAction) selectFavorite:(id) sender
{
NSLog(@"TEST");
}
The error I have is:
2011-03-12 20:48:33.861 SmarTrek[22040:207] -[RouteViewController selectFavorite]: unrecognized selector sent to instance 0x5b154a0
2011-03-12 20:48:33.863 SmarTrek[22040:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException'
The code is:
- (void)viewDidLoad
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateHighlighted];
button.bounds = CGRectMake(0, 0, 0, 29);
button.imageEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 0);
[button addTarget:self action:@selector(selectFavorite) forControlEvents:UIControlEventTouchUpInside];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateHighlighted];
button1.bounds = CGRectMake(0, 0, 0, 29);
button1.imageEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 0);
[button1 addTarget:self action:@selector(selectFavorite) forControlEvents:UIControlEventTouchUpInside];
origin.rightView = button;
destination.rightView = button1;
origin.rightViewMode = UITextFieldViewModeAlways;
destination.rightViewMode = UITextFieldViewModeAlways;
self.navigationItem.title = @"Where to go?";
//self.navigationItem.leftBarButtonItem;
//self.navigationItem.rightBarButtonItem;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (IBAction) selectFavorite:(id) sender
{
NSLog(@"TEST");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@selector(selectFavorite)
和@selector(selectFavorite:)
引用的方法不一样,冒号很重要。由于您的方法是- (IBAction) selectFavorite:(id) sender
,因此您需要在@selector
中包含冒号。The methods referred to by
@selector(selectFavorite)
and@selector(selectFavorite:)
are not the same, the colon is significant. Since your method is- (IBAction) selectFavorite:(id) sender
, you need to include the colon in the@selector
.