为什么我的方法不能完全正常工作? (iPhone SDK)

时间:2010-02-12 21:35:25

标签: iphone sdk console uibutton nslog

我的代码中有一个方法:

-(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调用确实有效并显示在控制台上。按钮开始读取开始录制,但按下它不会做什么,即使它与Interface Builder中的Touch Up Inside绑定以调用此方法并被引用。

1 个答案:

答案 0 :(得分:3)

你的问题就在这一行:

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

你在比较指针,而不是字符串。你需要:

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