gpt4 book ai didi

iphone - UIAlert View - 是/否条件

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

我的应用程序需要警报消息,如果按下"is"按钮,则再发出一个警报消息,然后我必须调用一个方法。这是我的代码:

-(IBAction)resetPressed:(id)sender
{
NSString *title= [NSString stringWithFormat:@"Warning"];
NSString *message = [NSString stringWithFormat:@"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:@"No"];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:ok otherButtonTitles:@"Yes",nil];
[alert show];
[alert release];
}


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alertView.tag ==1)
{
NSString *title= [NSString stringWithFormat:@"Warning"];
NSString *message = [NSString stringWithFormat:@"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:@"No"];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:ok otherButtonTitles:@"Yes",nil];
alert.tag =2;
[alert show];
[alert release];

}
else if(alertView.tag ==2)
{
[self resetArray];
}
}

谢谢。

最佳答案

我不确定您的目标是什么,但无论如何,有些事情对我来说似乎是错误的:

首先,您应该这样创建字符串:

NSString *title= @"Warning";

在您的情况下无需使用stringWithFormat

然后,您似乎没有正确地将第一个 UIAlert 的标记设置为 1,并且标记的默认值为 0,所以我猜测 didDismissWithButtonIndex 中的 if 语句从来都不是真的。

此外,您应该使用 buttonIndex 检查按下了哪个按钮,否则您将显示警报并调用 [self resetArray] 无论用户按下哪个按钮.

希望有帮助。

关于iphone - UIAlert View - 是/否条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3170425/

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