How are multiple UIActionSheet
s added to a single UIViewController
if there is only a single -actionSheet:clickedButtonAtIndex:
method?
Multiple UIActionSheets in one View Controller
Asked Answered
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
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 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)
{
}
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.
© 2022 - 2024 — McMap. All rights reserved.