IPHONE:UIAlertView在自定义函数/IBAction中被调用了两次 [英] IPHONE: UIAlertView called twice in a custom function/IBAction

查看:83
本文介绍了IPHONE:UIAlertView在自定义函数/IBAction中被调用了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IBAction进行一些处理,并且其中将有一些UIAlertViews(以显示警报).但是,该段中的第一个警报似乎被称为TWICE(在我单击后立即发生,而在所有其他警报发生后又发生一次).此外,第一次出现警报时,即使我有一个确定"按钮并且用户没有单击它,警报也会自动关闭.第二次出现警报,它将要求用户单击确定".

i have an IBAction which does some processing and within will have a few UIAlertViews (to show alerts). However it seems that the FIRST alert in the paragraph is being called TWICE (once immediately after i clicked and another time after all the other alerts has occured). Additionally, the first time the alert appears, the alert automatically closes even though i have an OK button and the user has not clicked on it. The 2nd time the alert appears, it will require the user to click on OK.

我尝试将段落从IBAction移到其自己的函数中,但仍然出现问题.

I tried moving the paragraph out from IBAction into its own function but still the problem occurs.

我的IBAction/功能中的所有警报均相同:

all the alerts in my IBAction/function are the same:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"blah" message:@"blah" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
   [alert show];
   [alert release];

但其他警报正常运行.

代码看起来像这样("blah"是被两次调用的代码):

the code looks like this ("blah" is the one being called twice):

-(void)function {
  if (......) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"blah" message:@"blah" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
         [alert show];
         [alert release];
     for (int i=0; i<2; i++) {
    if (.....) {
          //do stuff
    } else {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"blah2" message:@"blah2" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
         [alert2 show];
         [alert2 release];
    }
     }
   } else {
UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:@"blah3" message:@"blah3" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
         [alert3 show];
         [alert3 release];
}
}

请帮助!

推荐答案

首先,我们需要更多代码来诊断您的问题.您提供的是不够的.

First of all, we need more code to diagnose your problem. What you provide is not sufficient.

第二,我曾经遇到过类似的问题:当未在该设备上设置她的电子邮件帐户的用户触发撰写电子邮件操作时,我要求我的应用显示一个UIAlertView.但是,当我在这种情况下在真实设备上测试代码时,连续显示了两个UIAlertViews,两个都是关于电子邮件帐户未设置问题.

Second, I once encountered a similar problem: when a compose an email action is triggered by the user who didn't set up her email account on that device, I asked my app to show an UIAlertView. However, when I tested my code on a real device with such a scenario, two consecutive UIAlertViews showed, one after another, both of which are about the email account not set up issue.

我终于弄清楚,当用户尝试撰写电子邮件时,如果未设置电子邮件帐户,则iOS系统将自动显示UIAlertView,这就是为什么当我只希望创建一个UIAlertViews时出现两个UIAlertViews的原因.

I finally figured out that the iOS system will automatically show an UIAlertView when the email account is not set up while a user tries to compose an email, which is why two UIAlertViews showed up when I only expected one.

希望有帮助.

这篇关于IPHONE:UIAlertView在自定义函数/IBAction中被调用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆