gpt4 book ai didi

ios - 为什么 clickedButtonAtIndex 方法甚至在 UIActionSheet 的外侧点击都被调用?

转载 作者:行者123 更新时间:2023-12-01 17:53:38 25 4
gpt4 key购买 nike

正如我的标题所说 clickedButtonAtIndex委托(delegate)方法被调用,甚至在 UIActionSheet 的外侧点击。
当我点击 UIButton 时会显示我的 actionSheet .
我的代码 UIActionSheet宣言。

-(void)btnComplexityTapped:(UIButton *) sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select your complexity" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Easy", @"Medium", @"High", nil];
[actionSheet showFromRect:sender.frame inView:self.view animated:YES];
[actionSheet release];
}

在委托(delegate)方法中
- (void)actionSheet:(UIActionSheet *)myActionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
[self.btnComplexity setTitle:@"Easy" forState:UIControlStateNormal];
}
else if(buttonIndex == 1)
{
[self.btnComplexity setTitle:@"Medium" forState:UIControlStateNormal];
}
else
{
[self.btnComplexity setTitle:@"High" forState:UIControlStateNormal];
}
}

我知道这个问题可以通过在委托(delegate)方法中设置最后一个条件来设置 else if(buttonIndex == 1)而不仅仅是 else .但我不想应用任何修复但我想知道 为什么即使我没有点击 UIActionSheet 的任何按钮也会调用委托(delegate)方法

请参阅此视频以获取更清晰的图片。

enter image description here

如上所述,当我单击按钮时,按钮的默认标题为“中”,然后 actionSheet 打开,我单击 actionSheet 的外侧(例如 self.view )然后委托(delegate)方法 clickedButtonAtIndex最后被称为 else条件变为真,这样我的按钮标题就变成了“高”。

任何人都可以告诉我为什么会这样吗?

最佳答案

在 iPad 中,操作表以弹出框的形式呈现。没有取消按钮,因为触摸弹出框相当于触摸取消。因此,您的代表会收到消息,就好像取消按钮已被触摸一样。

关于ios - 为什么 clickedButtonAtIndex 方法甚至在 UIActionSheet 的外侧点击都被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22370939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com