gpt4 book ai didi

ios - UIActionSheet取消按钮无法正常工作

转载 作者:行者123 更新时间:2023-12-01 20:13:17 26 4
gpt4 key购买 nike

UIActionSheet,它具有带有标题的按钮,我正在从数组中获取标题。我想获取按钮的标题并以UILabel显示,我这样做了,但是如果我按取消按钮,取消按钮也会显示,我不想显示UILabel中的取消按钮标题
下面我尝试过的代码,

 - (IBAction)site_Selection:(id)sender {

NSArray *array = @[@"one",@"two",@"three",@"Smart Gladiator1"];

UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
actionSheet.delegate = self;
for (NSString *title in array) {
[actionSheet addButtonWithTitle:title];
}

actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];


[actionSheet showInView:self.view];


}

-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];


self.btn_site_selection.titleLabel.text = [actionSheet buttonTitleAtIndex:buttonIndex];

}

请帮助我做到这一点,

最佳答案

您不应该处理取消按钮的按下。

由于所有按UIActionSheet的按钮都由actionSheet:clickedButtonAtIndex:处理,因此您需要检查按钮索引是否为取消按钮的索引。您可以使用cancelButtonIndex上的UIActionSheet来做到这一点:

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet.cancelButtonIndex == buttonIndex) {
return;
}

}

关于ios - UIActionSheet取消按钮无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37295429/

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