views:

75

answers:

3

One of my views uses 3 action sheets that come from when various buttons are 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?

+4  A: 

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

AtomRiot
A: 

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

karim
A: 

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.

nickthedude
Yes they do. I think the tag method is much cleaner.
Nic Hubbard