2

私のビューの 1 つは、さまざまなボタンがクリックされたときに表示される 3 つのアクション シートを使用します。メソッドが 1 つしかないので- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex、どのアクション シートを扱っているかを知る最善の方法は何ですか? actionSheets の最初のボタンを選択すると、buttonIndex 0 になります。そのため、どの actionSheet 呼び出しから来ているかを知る方法を知る必要があります。

アイデア?

4

4 に答える 4

10

アクション シートを作成するときにタグを設定し、アクション シート メソッドでそれに対してテストする必要があります。

于 2010-08-13T06:31:40.333 に答える
1

私は同じ問題を抱えていたので、アクションシートのタイトルに基づいて条件を設定しました:

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


if (actionSheet.title == @"present action sheet A") {

//do some stuff

}
if (actionSheet.title == @"present action sheet B") {

//do some stuff

}

アクションシートにタグが付いているかどうかはわかりませんが、間違っているかもしれません。

于 2010-10-15T19:27:41.203 に答える
0

3 アクションシートにはクラス レベル変数を使用します。次に、actionSheet メソッドでアクションのソースを比較できます。

于 2010-08-13T08:26:43.367 に答える
0

アクション作成時にタグを設定する

UIActionSheet * actionSheet = 
[[UIActionSheet alloc] 
initWithTitle:@"My title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil  otherButtonTitles:@"Option1",@"Option2", nil];

actionSheet.tag = 1100;





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

{

if(actionSheet.tag == 1100)
{

    switch (buttonIndex) 
    {
        case 0: 
        {  
        }
           break;
        case 1:
        {

        }
            break;
        default:
            break;
    }  
}  
}
于 2014-08-07T13:43:12.933 に答える