0

iOS デバイス用のアプリケーションを作成していますが、下の画像ではいくつかのエラーがあります。 ここに画像の説明を入力

ご覧のとおり、すべて同じですが、エラーの意味しかありませんでした。リンクのコードを追加しました(apple、google、yahoo、

何がうまくいかなかったのかわかりませんが、エラーを止めるために何を変更する必要があるか教えていただければ幸いです。


ご覧のとおり、以下の show alert コードのみがありますが、Xcode には他の 10 個のコードがあります。すべてのスペースを占有したくなかったので、次のように名前を付けました

showAlertOO showAlert1 showAlert2 showAlert3 showAlert4 showAlert5 showAlert6 showAlert7 showAlert8 showAlert9

私の言いたいことが理解できたら

  - (void) showAlert {

        UIAlertView *alert = [[UIAlertView alloc]

                              initWithTitle:@"hello"
                              message:@"whats you name" 
                              delegate:nil 
                              cancelButtonTitle:@"Dismiss" 
                              otherButtonTitles:@"apple", @"google" , @"yahoo", nil]; 



        [alert show];

わかりましたので、これはボタンを機能させるために追加したコードであり、これがエラーを引き起こした原因です。

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

if (buttonIndex == 1) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apple.com/uk"]]; 
        }
    if (buttonIndex == 2) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]]; 
    }
        if (buttonIndex == 3) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.yahoo.com"]]; 
        }

以下のコードはすべて問題なく、ここにエラーはありません。私が持っているセットアップを皆さんに見てもらいたかっただけです。

 -(IBAction)plus {
        counter=counter + 1;
        count.text = [NSString stringWithFormat:@"%i",counter];
        if(counter == 100)
            [self showAlert];
        if(counter == 500)
            [self showAlert00];
        if(counter == 1000)
            [self showAlert1];
        if(counter == 2500)
            [self showAlert2];
        if(counter == 5000)
            [self showAlert3];
        if(counter == 7500)
            [self showAlert4];
        if(counter == 10000)
            [self showAlert5];
        if(counter == 15000)
            [self showAlert6];
        if(counter == 20000)
            [self showAlert7];
        if(counter == 25000)
            [self showAlert8];
        if(counter == 30000)
            [self showAlert9];
        if(counter == 35000)
            [self showAlert10];
    }



    -(IBAction)zero {
        counter=0;
        count.text = [NSString stringWithFormat:@"%i",counter];
    }




    - (void)viewDidLoad {
        counter=0;
        count.text = @"0";
            [super viewDidLoad];

    }

ありがとうございました。

4

1 に答える 1

1

実際に使用する前に、セレクター'showAlert' ...'showAlert10'を宣言しましたか?そうでない場合は、プライベートカテゴリ(.mファイルの先頭)で宣言できます。

ちなみに...「showAlert5」ではなく、わかりやすい名前を使用することを強くお勧めします。これにより、最終的には前後に移動する時間を節約できます...これだけでなく、コード内のあらゆる場所で使用できます。

于 2012-07-14T15:07:44.050 に答える