2011-10-01 13 views
3

私はUIActionSheetで '破壊的な'ボタンが押されているかどうかを判断するために必要なコード行を整えようとしています。「破壊的」ボタンが押された(UIActionSheet - iPhone)かどうかを確認するにはどうすればいいですか?

私は周りを見ていたし、デリゲートメソッドを見つけた

...

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

を...と私も[myActionSheet destructiveButtonIndex]を見つけることができた、私はちょうど2つを一緒に入れてするかどうかはわかりません。

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == destructiveButtonIndex) 
    { 
     // Do something... 
    } 
} 

答えて

11

の下にあなたがあなたのコードと非常に接近していたようにチェックする必要があります。これは私がいない成功を収めてこれまでにしようとしているものです。あなたが探している実装は:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == actionSheet.destructiveButtonIndex) 
    { 
     // Do something... 
    } 
} 
+0

ありがとうございます - それは私が探していたものです。私は近いと分かっていた;) –

+0

多くの感謝!このゲッターについて知りませんでした。本当に素晴らしい – aumanets

-2

あなたは

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    { 
     // Do something... 
    } 
    else if (buttonIndex == 1) 
    { 

    } 
} 
+3

間違っています。 OPはdestructiveButtonを特に探しています。これを見つけるためにUIActionSheetにプロパティがあります。 –

関連する問題