gpt4 book ai didi

objective-c - actionSheet clickedButtonAtIndex 在 objective-c 中不起作用?

转载 作者:行者123 更新时间:2023-11-29 13:41:37 24 4
gpt4 key购买 nike

我尝试单击按钮,从操作表中选择,然后将所选索引设置为按钮文本标签的文本。我的按钮在下面。但它不会在按钮文本中显示选定的索引。我该如何解决这个问题?

- (IBAction)cinsiyetBtnClick:(id)sender {
popupQuery1 = [[UIActionSheet alloc] initWithTitle:@"Cinsiyetiniz"
delegate:self
cancelButtonTitle:NO
destructiveButtonTitle:NO
otherButtonTitles:@"Bay", @"Bayan",nil];
popupQuery1.tag = 1;
// popupQuery1.actionSheetStyle = UIActionSheetStyleDefault;
[popupQuery1 showInView:[UIApplication sharedApplication].keyWindow];
[popupQuery1 release];
}

- (IBAction)medeniDurumBtnClick:(id)sender {
popupQuery1 = [[UIActionSheet alloc] initWithTitle:@"Medeni Durumunuz"
delegate:self
cancelButtonTitle:NO
destructiveButtonTitle:NO
otherButtonTitles:@"Evli", @"Bekar",@"Dul",@"Boşanmış",nil];
popupQuery1.tag = 2;
// popupQuery1.actionSheetStyle = UIActionSheetStyleDefault;
[popupQuery1 showInView:[UIApplication sharedApplication].keyWindow];
[popupQuery1 release];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(actionSheet.tag==1){
if (buttonIndex == 0) {
self.cinsiyetBtn.titleLabel.text = @"Bay";
} else if (buttonIndex == 1) {
self.cinsiyetBtn.titleLabel.text = @"Bayan";
}
}
else if (actionSheet.tag == 2){
if (buttonIndex == 0) {
self.medeniDurumBtn.titleLabel.text = @"Evli";
} else if (buttonIndex == 1) {
self.medeniDurumBtn.titleLabel.text = @"Bekar";
} else if (buttonIndex == 2) {
self.medeniDurumBtn.titleLabel.text = @"Dul";
} else if (buttonIndex == 3) {
self.medeniDurumBtn.titleLabel.text = @"Boşanmış";
}
}
}

最佳答案

按钮有几种状态:UIControlStateNormalUIControlStateHighlightedUIControlStateSelectedUIControlStateDisabled

在大多数情况下,当你想更新按钮的标题时,你应该为正常状态设置新标题:

[button setTitle:@"New Title" forState:UIControlStateNormal];

有时您需要为所有州设置标题。

所以现在您应该将所有 self.cinsiyetBtn.titleLabel.text = @"Bay"; 替换为如下内容:

[self.cinsiyetBtn setTitle:@"Bay" forState:UIControlStateNormal];

关于objective-c - actionSheet clickedButtonAtIndex 在 objective-c 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8971942/

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