Multiple UIActionSheets in one View Controller
Asked Answered
P

3

5

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

Purposive answered 24/2, 2011 at 7:27 Comment(0)
O
7

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

Ostrich answered 24/2, 2011 at 7:36 Comment(2)
Thanks. Do you know how to set the button colors? e.g. a red Delete button?Purposive
@Helium3: Red color is by default color for destructive button titles in actionsheet. You just have to declare destructiveButtonTitle=@"Delete" while declaring actionsheet. Hope this helps you.Lexical
P
3

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)
{
}
Penuchle answered 18/11, 2011 at 9:28 Comment(0)
B
2

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.

Bufordbug answered 24/2, 2011 at 7:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.