Search code examples
ioscocoa-touchios6

Wait until the next layout update (end of layout update cycle) before executing some code


I have code that invalidates the layout of a UICollectionView. I want to wait until the layout has updated before executing some code.

Does the layout get updated in the main queue? And if so, dispatching my code to the main queue would ensure it's executed after, correct? This doesn't seem to be the case however, as my code does appear to be executed beforehand.


Solution

  • [self performSelector:@selector(someMethod) withObject:objectOrNil afterDelay:0.0f]; might help you. Calling a method with the code you want to execute after a delay of 0.0 seconds will wait until the current run cycle is over, it will not run the very instance it is called.