some_id
some_id

Reputation: 29896

Multiple UIActionSheets in one View Controller

How are multiple UIActionSheets added to a single UIViewController if there is only a single -actionSheet:clickedButtonAtIndex: method?

Upvotes: 5

Views: 2819

Answers (3)

Aakil Ladhani
Aakil Ladhani

Reputation: 982

You can create multiple action sheet as below:

actionSheet1 = [[UIActionSheet alloc] initWithTitle:@"Where to go"
                                                   delegate:self
                                          cancelButtonTitle:@"cancel"
                                     destructiveButtonTitle:@"Store 2"
                                          otherButtonTitles:@"Store 3",@"Store 4",@"Store 5",@"View Store Profile",nil];
 actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Where to go"
                                                   delegate:self
                                          cancelButtonTitle:@"cancel"
                                     destructiveButtonTitle:@"Store 1"
                                          otherButtonTitles:@"Store 3",@"Store 4",@"Store 5",@"View Store Profile",nil];
actionSheet3 = [[UIActionSheet alloc] initWithTitle:@"Where to go"
                                                   delegate:self
                                          cancelButtonTitle:@"cancel"
                                     destructiveButtonTitle:@"Store 1"
                                          otherButtonTitles:@"Store 2",@"Store 4",@"Store 5",@"View Store Profile",nil];

& after that chek out which action sheet is called by - (void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{

if(actionSheet==actionSheet1)
{
}
else if(actionSheet==actionSheet2)
{
}
else if(actionSheet==actionSheet3)
{
}

Upvotes: 3

Sat
Sat

Reputation: 1626

Set a Name or Tag to your Action sheet and do some thing like this

  -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
 {
   if(actionSheet==yourActionsheet1)
     {
      //your logic
       }
     if(actionSheet==yourActionsheet2)
     {
      //your logic
       }
    }

hope this help

Upvotes: 7

visakh7
visakh7

Reputation: 26400

You can add multiple action sheets to the same view controller. You can set a tag for each of the action sheets and check the tag in the delegate method to perform the necessary function.

Upvotes: 2

Related Questions