0

ここに私のコードにあるメソッドがあります:

-(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 呼び出しが機能し、コンソールに表示されます。このボタンは、Begin Recording と読み始めますが、このメソッドを呼び出すために Interface Builder の Touch Up Inside と結び付けられて参照されているにもかかわらず、ボタンを押しても何も起こりません。

4

1 に答える 1

3

あなたの問題はこの行です:

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

そこでは、文字列ではなくポインターを比較しています。必要なもの:

if ([actionButton.titleLabel.text isEqualToString:@"Begin Recording"]){
于 2010-02-12T21:37:52.730 に答える