2

我的一个观点使用了 3 个动作表,这些动作表是在单击各种按钮时产生的。由于我只有一种- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex方法,知道我正在处理哪个操作表的最佳方法是什么?选择我的任何 actionSheet 上的第一个按钮将是 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方法中比较action的来源。

于 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 回答