将 UIButton 添加到 UITextField 导致发送无法识别的选择器

发布于 2024-10-21 12:46:09 字数 1758 浏览 1 评论 0原文

我的错误是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-10-28 12:46:09

@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文