Почему мой метод не работает полностью? (iPhone SDK) - PullRequest
0 голосов
/ 13 февраля 2010

У меня есть метод, который есть в моем коде:

-(IBAction) actionButtonPressed: (id) sender{
    NSLog(@"%@",actionButton.titleLabel.text);
    if (actionButton.titleLabel.text == @"Begin Recording"){
        [actionButton setTitle:@"Finish Recording" forState:UIControlStateNormal];
        [actionButton setTitle:@"Finish Recording" forState:UIControlStateApplication];
        [actionButton setTitle:@"Finish Recording" forState:UIControlStateHighlighted];
        [actionButton setTitle:@"Finish Recording" forState:UIControlStateReserved];
        [actionButton setTitle:@"Finish Recording" forState:UIControlStateSelected];
        [actionButton setTitle:@"Finish Recording" forState:UIControlStateDisabled];
        UIImage *redButton = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bigredbutton" ofType:@"png"]];
        [actionButton setBackgroundImage:redButton forState:UIControlStateNormal];
        [actionButton setBackgroundImage:redButton forState:UIControlStateApplication];
        [actionButton setBackgroundImage:redButton forState:UIControlStateHighlighted];
        [actionButton setBackgroundImage:redButton forState:UIControlStateReserved];
        [actionButton setBackgroundImage:redButton forState:UIControlStateSelected];
        [actionButton setBackgroundImage:redButton forState:UIControlStateDisabled];
    }
    if (actionButton.titleLabel.text == @"Finish Recording"){
        [self dismissModalViewControllerAnimated:YES];
    }

}

По какой-то причине вызов NSLog работает и отображается на консоли. Кнопка начинает читать «Начать запись», но нажатие на нее ничего не делает, даже если она связана с «Touch Up Inside» в Интерфейсном Разработчике для вызова этого метода и имеет ссылку.

1 Ответ

3 голосов
/ 13 февраля 2010

Ваша проблема в этой строке:

if (actionButton.titleLabel.text == @"Begin Recording"){

Там вы сравниваете указатели, а не строки. Вам нужно:

if ([actionButton.titleLabel.text isEqualToString:@"Begin Recording"]){
...