开发者

iPhone: Handle multiple action sheets

One of my views uses 3 action sheets that come from when various buttons a开发者_C百科re clicked. Since I only have one - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex method, what is the best way to know which action sheet I am dealing with? Choosing the first button on any of my actionSheets would be buttonIndex 0. So I need to know how to know which actionSheet call that is coming from.

Ideas?


You need to set the tag when you create the action sheet and test against that in your action sheet method.


I had the same issue and I simply set up a conditional based on the action sheet's title:

in

- (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

}

Works like a charm, not sure if action sheets have tags, maybe im wrong though.


Use class level variable for 3 actionsheet. Then you can compare the source of action in the actionSheet method.


Set the Tag when you create an action

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;
    }  
}  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜