[英]UIActionSheet, cancel button runs method
Every time I press a cancel button in UIActionSheet, it runs a method. 每次我按下UIActionSheet中的“取消”按钮时,它都会运行一个方法。 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
. 因此它运行方法
showPineapple
。 Please help ! 请帮忙 !
Ya when you press cancel button on action sheet then it's delegate function always call, with the last index. 是的,当您按下操作表上的“取消”按钮时,它的委托函数始终会调用,并带有最后一个索引。
If you are implementing multiple actionsheet then just use it by tag value. 如果要实现多个操作表,则只需按标记值使用即可。
You need to implement something like this: 您需要实现以下内容:
Change your if
and else
sections to add a unique tag for each UIActionSheet: 更改您的
if
和else
部分,为每个UIActionSheet添加一个唯一标签:
if(![giftTitle isEqualToString:@"bla"]) {
actionSheet = [[UIActionSheet alloc]initWithTitle:giftTitle
delegate:self
cancelButtonTitle:@"Back"
destructiveButtonTitle:nil
otherButtonTitles:@"Send via email", @"Read in Wikipedia" , nil];
actionSheet.tag = 10;
} else {
actionSheet = [[UIActionSheet alloc]initWithTitle:giftTitle
delegate:self
cancelButtonTitle:@"Back"
destructiveButtonTitle:nil
otherButtonTitles:@"Send via email", @"Read in Wikipedia", @"Pineapple mode", nil];
actionSheet.tag = 20;
}
Then look for the tag in the actionSheet:clickedButtonAtIndex: message handler: 然后在actionSheet:clickedButtonAtIndex:消息处理程序中查找标记:
case 2:
if (actionSheet.tag == 20)
[self showPineapple];
break;
This means [self showPineapple]
will only run in the else
scenario, while nothing will happen in the if
scenario (just as nothing will happen for buttonIndex
3 in the else
scenario (where the Cancel button is indeed at index 3) . 这意味着
[self showPineapple]
将只在运行else
方案,而什么都不会在发生if
方案(就像什么都不会发生了buttonIndex
在3 else
情形(其中取消按钮确实是在指数3)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.