1

I have a block completion being called from within a button press message and, depending on state, optionally a UIAlertView being displayed. However, when invoked the UIAlertView appears three (3) times...

  1. With the full information but it disappears itself and shows
  2. Just the title shows and when I click OK
  3. Appears again with full information (as in #1) for which I have to dismiss again

Following is a snippet of the code:

        [credential performDataOperation:[credential commandForCreateOnClass:self.className]
                       withArguments:edits
                     completionBlock:^(BOOL succeded, id before, id after, NSDictionary *arguments, NSError *error) {
                         if (succeded) {
                             self.object = after;
                             self.objectWasCreated = YES;
                             [self prepareEditsDictionary];
                             self.navigationItem.rightBarButtonItem.enabled=NO;
                         }
                         else {
                             errorRecieved = YES;
                             [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Error Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

                         }
                     }];
4

1 回答 1

1

您可能只看到两个警报。第一个出现,但您在某处也有调用第二个的代码,因此它会覆盖第一个。然后你解雇第二个,第一个返回。您需要寻找显示第二个警报的代码,即没有消息的代码,并找出该代码运行的原因。只需在您的项目中进行全局搜索UIAlertView!它必须在某个地方,因为所有警报视图都是在代码中创建和呈现的。

您可能不小心连接了您的按钮,使其具有多个操作处理程序。当然我可能是错的,但这是我有时会犯的一个错误,然后我很困惑为什么我的方法被调用了两次,或者当我点击按钮时发生了一些不需要的额外事情。检查您的笔尖/故事板或代码以确保。单个按钮可以对单个 UIControlEvent 执行多个操作这一事实非常令人惊讶,并且几乎从未有意使用过。

(如果这不是正确的答案,那么解决方案可能在于您的performDataOperation方法,您没有显示其代码。除了调用块之外,它还可能调用更简单的 UIAlertView。

于 2013-04-27T16:22:55.237 回答