Make UIAlertView blocking

后端 未结 5 2047
刺人心
刺人心 2020-12-03 12:49

I need make UIAlertView blocking. Because i have function and i need to return UIAlertView choice. But problem is that after UIAlertView

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 12:56

    I was just facing the same problem. Although no solution, there are at least 2 workarounds that I thought of.

    Loop "solution" Right after you call the UIAlert you start a loop that looks for the change in a variable that is global to your object (not to the whole project, mind you) that variable is the one you set in the UIAlert delegate that takes the answers. So basically you wait for "is A == 1, if not DoEvents" and loop on it.

    Then on the delegate you make A=1 when you have the answer

    and before someone says that there is no DoEvents in Cocoa:

    void MyTestClass::DoEvents()
    {
    
      NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
      NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
        untilDate:[NSDate distantPast]
        inMode:NSDefaultRunLoopMode
        dequeue:YES];
      if (event) {
        [NSApp sendEvent:event];
        [NSApp updateWindows];
      }
      [pool release];
    }
    

    Delegate Solution Instead of having the code that deals with Answer A, B or C in the function that calls the Alert, have the code in the delegate itself.

    Hope it helps. I used the second one in my project and it worked.

提交回复
热议问题