gpt4 book ai didi

iphone - UIActionSheet 进行多个 UIButton 更改

转载 作者:行者123 更新时间:2023-11-29 05:05:29 25 4
gpt4 key购买 nike

我的 View 上有 6 个 UI 按钮。我试图为每个按钮调用 UIActionSheet,并更改按钮图像和 UIlabel。我可以让第一个按预期工作。我似乎无法让第二个像第一个那样进行更改。这是我的代码。请帮忙。

-(IBAction)lifeStatus:(id)sender {

UIActionSheet *lifeStatus = [[UIActionSheet alloc] initWithTitle:@"Please Select" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"UNSECURED" otherButtonTitles:@"SECURED", @"PENDING", nil];


lifeStatus.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[lifeStatus showInView:self.view.window];
[lifeStatus release];

}
-(void)actionSheet:(UIActionSheet *)lifeStatus clickedButtonAtIndex:(NSInteger) buttonIndex {
if (buttonIndex == 0) {
self.lifeLabel.text = @"UNSECURED";
[self.lifeButton setImage:[UIImage imageNamed:@"RedButton.png"] forState:UIButtonTypeCustom];
self.lifeLabel.textColor = [UIColor whiteColor];
} else if (buttonIndex == 1) {
self.lifeLabel.text = @"SECURED";
[self.lifeButton setImage:[UIImage imageNamed:@"GreenButton.png"] forState:UIButtonTypeCustom];
self.lifeLabel.textColor = [UIColor whiteColor];
} else if (buttonIndex == 2) {
self.lifeLabel.text = @"PENDING";
[self.lifeButton setImage:[UIImage imageNamed:@"YellowButton.png"] forState:UIButtonTypeCustom];
self.lifeLabel.textColor = [UIColor blackColor];
}
}

-(IBAction)sceneStatus:(id)sender {

UIActionSheet *sceneStatus = [[UIActionSheet alloc] initWithTitle:@"Please Select" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"UNSECURED" otherButtonTitles:@"SECURED", @"PENDING", nil];

sceneStatus.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[sceneStatus showInView:self.view.window];
[sceneStatus release];

}

-(void)actionSheet1:(UIActionSheet *)sceneStatus clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
self.sceneLabel.text = @"UNSECURED";
[self.sceneButton setImage:[UIImage imageNamed:@"RedButton.png"] forState:UIButtonTypeCustom];
self.sceneLabel.textColor = [UIColor whiteColor];
} else if (buttonIndex == 1) {
self.sceneLabel.text = @"SECURED";
[self.sceneButton setImage:[UIImage imageNamed:@"GreenButton.png"] forState:UIButtonTypeCustom];
self.sceneLabel.textColor = [UIColor whiteColor];
} else if (buttonIndex == 2) {
self.sceneLabel.text = @"PENDING";
[self.sceneButton setImage:[UIImage imageNamed:@"YellowButton.png"] forState:UIButtonTypeCustom];
self.sceneLabel.textColor = [UIColor blackColor];
}
}

最佳答案

使用默认按钮创建 UIActionSheet。在每个按钮上点击设置您需要在 actionSheet 中显示的按钮标题。

for (int i = 0; i < itemCount; i++) {
[actionSheet addButtonWithTitle:itemText];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];

关于iphone - UIActionSheet 进行多个 UIButton 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5446542/

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