[英]IOS: stop a loop of UIAlert
I have this code:我有这个代码:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
}
else if(buttonIndex == 1)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Danger"
message:@"war"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
but but every time i push ok of this UIAlert it return inside this delegate method;但是每次我按下这个 UIAlert 的确定时,它都会返回这个委托方法中; how can I solve this thing?
我该如何解决这个问题? Can I use a BOOL for the control?
我可以使用 BOOL 进行控制吗?
Set the delegate of the second alertView
to nil.将第二个
alertView
的委托设置为 nil。
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Danger"
message:@"war"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
However, if you wish to add options to the second on in the future, you can set a tag
value to the alertView
and check the tags on call of the delegate method.但是,如果您希望将来在第二个上添加选项,您可以为
alertView
设置一个tag
值,并在调用委托方法时检查标签。 Depending on the tag
value you would perform a different task.根据
tag
值,您将执行不同的任务。
You can set the tag
property of the altertView to 1 like this您可以像这样将 alterView 的
tag
属性设置为 1
alertView.tag = 1;
and change your code to:并将您的代码更改为:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if ([alertView tag] != 1) {
if(buttonIndex == 0)
{
}
else if(buttonIndex == 1)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Danger"
message:@"war"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
alertView.tag = 1;
[alertView show];
[alertView release];
}
}
}
You could also change the delegate of the alert view.您还可以更改警报视图的委托。
you can't stop it until and unless you set the delegate
property nil
.除非您设置
delegate
属性nil
,否则您无法停止它。
Use as below如下使用
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
}
else if(buttonIndex == 1)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Danger"
message:@"war"
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
alertView.tag = 1;
[alertView show];
[alertView release];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.