2011-01-20 6 views
0

最近私はiOS開発に関する研究を開始しました。alertView didDismissWithButtomIndexはalertViewのボタンをクリックしても呼び出されません

アプリケーションのビューが読み込まれると、いくつかのキーの設定がチェックされ、これらのキーの値がない場合、アプリケーションは警告を表示して終了する必要があります。

まず第一に、私はUIAlertViewDelegate実装しました:

@interface FirstViewController : UIViewController <UIAlertViewDelegate> { 
... 

を[設定]にチェック:

- (void)viewDidLoad { 
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

       NSString *url = [defaults stringForKey:@"url"]; 
      NSString *apiKey = [defaults stringForKey:@"api-key"]; 

      if([url length] < 1 || [apiKey length] < 1){ 
      UIAlertView *dialog = [[[UIAlertView alloc] 
         initWithTitle:@"Not properly configured" 
         message:@"This application was not properly configured. Please configure the application on your iPhone settings." 
       delegate:self 
       cancelButtonTitle:@"Close" 
       otherButtonTitles:nil] 
       autorelease]; 
     [dialog setTag:1]; 
     [dialog show]; 
    } 

    [url release]; 
    [apiKey release]; 
    [super viewDidLoad]; 
} 

私はalertViewの解任後方法alertView didDismissWithButtomIndexが呼び出されるべきであることを理解するが、何らかの理由でこのメソッドが私のコードで呼び出されることはありません。

- (void)alertView:(UIAlertView *)alertView     didDismissWithButtomIndex:(NSInteger)buttomIndex { 
       if([alertView tag] == 1){ 
       exit(0); 
       } 
} 

なぜこれが起こっている上の任意のアイデア?あなたは間違った方法のために聞いている

答えて

4

didDismissWithButtonIndexのスペルが間違っていると、 'n'の代わりに 'm'をスヌーズします。

+0

+1鮮明な目の場合。そのようなバグは最悪ですね。私は一度WebページのonLickイベントをバインドしようと非常にイライラした午後を過ごした...ダングそれ! –

+0

@ダンレイ - APIをよく知っていないと、特にうんざりするので、APIを使用するときにミススペルではなくエラーではないと想定できません。 PS:これの後、私は間違いなく眼科医に行きます。 – Raphael

1

、あなたが実装する必要があります。docに

alertView:clickedButtonAtIndex: 

をあなたはdismissWithClickedButtonIndexときdidDismissWithButtomIndexが呼び出されたことを読むことができます:アニメーション:alertViewに呼ばれています。

alertView:didDismissWithButtonIndex:アラートビューが画面から却下された後 がデリゲートに送信されます。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if(buttonIndex == ...) { 
    // do something 
    } 
} 

PS:あなたのコードが動作するために

だから、あなたは次のようにimplementsomething必要があります(0)、それはアプリケーションを強制終了するにはiOSの悪い習慣があるの出口を呼び出すべきではありません。ユーザーはホームボタンでアプリを終了するはずです。

関連する問題