gpt4 book ai didi

xcode - 多个 UIAlertView;每个都有自己的按钮和 Action

转载 作者:行者123 更新时间:2023-12-03 14:26:53 24 4
gpt4 key购买 nike

我在 Xcode 4.3 中创建了一个 View ,我不确定如何指定多个 UIAlertView,这些 UIAlertView 有自己的按钮和单独的操作。目前,我的警报有自己的按钮,但操作相同。下面是我的代码。

-(IBAction)altdev {
UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@"titleGoesHere"
message:@"messageGoesHere"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Continue", nil];
[alert show];
}

-(IBAction)donate {
UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@"titleGoesHere"
message:@"messageGoesHere"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Continue", nil];
[alert show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite1.com"]];
}
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"examplesite2.com"]];
}
}

谢谢你的帮助!

最佳答案

有一个有用的属性 tagUIView (其中 UIAlertView 子类来自)。您可以为每个警报 View 设置不同的标签。

更新:

#define TAG_DEV 1
#define TAG_DONATE 2

- (IBAction)altdev {
UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@"titleGoesHere"
message:@"messageGoesHere"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Continue", nil];
alert.tag = TAG_DEV;
[alert show];
}

- (IBAction)donate {
UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@"titleGoesHere"
message:@"messageGoesHere"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Continue", nil];
alert.tag = TAG_DONATE;
[alert show];
}

-(void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == TAG_DEV) { // handle the altdev
...
} else if (alertView.tag == TAG_DONATE){ // handle the donate

}
}

关于xcode - 多个 UIAlertView;每个都有自己的按钮和 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9553493/

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