добавление UIButton в UITextField, вызывая отправку нераспознанного селектора - PullRequest
0 голосов
/ 13 марта 2011

У меня ошибка:

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");

}

1 Ответ

1 голос
/ 13 марта 2011

Методы, на которые ссылаются @selector(selectFavorite) и @selector(selectFavorite:), не одинаковы, двоеточие является значимым. Поскольку ваш метод - (IBAction) selectFavorite:(id) sender, вам необходимо включить двоеточие в @selector.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...