actionSheet clickedButtonAtIndex 在 Objective C 中不起作用?
我尝试单击按钮,从操作表中选择,然后将所选索引设置为按钮文本标签的文本。我的按钮在下面。但它不会在按钮文本中显示选定的索引。我该如何解决这个问题?
- (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ış";
}
}
}
I try to click button, select from action sheet and then set the selected index to the button text label's text. My button is below. But it not show selected index in button text. How can I solve this?
- (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ış";
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按钮可能处于多种状态:
UIControlStateNormal
、UIControlStateHighlighted
、UIControlStateSelected
和UIControlStateDisabled
。在大多数情况下,当您想要更新按钮的标题时,您应该为正常状态设置新标题:
有时您需要为所有状态设置标题。
因此,现在您应该将所有
self.cinsiyetBtn.titleLabel.text = @"Bay";
替换为如下内容:There are several states in which button could be:
UIControlStateNormal
,UIControlStateHighlighted
,UIControlStateSelected
andUIControlStateDisabled
.In most cases when you want to update title of button you should set new title for normal state:
Sometimes you would need to set titles for all the states.
So now you should just replace all your
self.cinsiyetBtn.titleLabel.text = @"Bay";
with something like this: