Every time I press a cancel button in UIActionSheet, it runs a method. I have no idea why, I checked whole my code many times, but I still can’t see the problem. Could you help me to find it ?
-(IBAction)moreOptions
{
giftTitle = self.title;
if(![giftTitle isEqualToString:@"bla"])
{
actionSheet = [[UIActionSheet alloc]initWithTitle:giftTitle
delegate:self
cancelButtonTitle:@"Back"
destructiveButtonTitle:nil
otherButtonTitles:@"Send via email",
@"Read in Wikipedia"
, nil];
}
else
{
actionSheet = [[UIActionSheet alloc]initWithTitle:giftTitle
delegate:self
cancelButtonTitle:@"Back"
destructiveButtonTitle:nil
otherButtonTitles:@"Send via email",
@"Read in Wikipedia", @"Pineapple mode"
, nil];
}
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view.window];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// выстраеваем дальнейшие действия кнопок
switch (buttonIndex)
{
case 0:
[self showPicker];
break;
case 1:
[self goWiki];
break;
case 2:
[self showPineapple];
break;
default:
break;
}
}
So it runs method showPineapple. Please help !
You need to implement something like this:
Change your
ifandelsesections to add a unique tag for each UIActionSheet:Then look for the tag in the actionSheet:clickedButtonAtIndex: message handler:
This means
[self showPineapple]will only run in theelsescenario, while nothing will happen in theifscenario (just as nothing will happen forbuttonIndex3 in theelsescenario (where the Cancel button is indeed at index 3) .