This is about Run Loop Modes.
Deferred operations that run on the main thread are typically scheduled for NSDefaultRunLoopMode
of the main run loop which means to not run when a menu or a modal dialog is open. You need to use NSRunLoopCommonModes
instead, which will allow them to run in both default and event tracking (menus, dialogs) modes.
For example:
if you are using
NSTimer
to fire update events, instead ofscheduledTimerWithTimeInterval
, usetimerWithTimeInterval
in combination with[[NSRunLoop currentRunLoop] addTimer:theTimer forMode:NSRunLoopCommonModes]
.if you are using
performSelectorOnMainThread:withObject:waitUntilDone:
, instead useperformSelectorOnMainThread:withObject:waitUntilDone:modes:
, passing[NSArray arrayWithObject:NSRunLoopCommonModes]
for themodes:
argument.