每次我在 UIActionSheet 中按下取消按钮时,它都会运行一个方法。我不知道为什么,我多次检查了整个代码,但我仍然看不到问题。你能帮我找到它吗?
-(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;
}
}
因此它运行方法showPineapple
。请帮忙!
最佳答案
是的,当您按下操作表上的取消按钮时,它的委托(delegate)函数总是会调用,并带有最后一个索引。
如果您要实现多个操作表,则只需按标记值使用它即可。
关于iphone - UIActionSheet,取消按钮运行方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12218298/