queued view updates not happening when performSelector afterDelay:0 used

Posted by JosephH on Stack Overflow See other posts from Stack Overflow or by JosephH
Published on 2010-05-06T19:31:59Z Indexed on 2010/05/06 19:48 UTC
Read the original article Hit count: 190

Filed under:
|
|

Hi all,

I have an app that performs some calculations based on data arriving on a socket or local user interaction.

I want to show an 'activity spinner' whilst the calculation happens.

spinner = [[UIActivityIndiactorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setCenter:self.view.center];
[self.view addSubview:spinner];
[spinner startAnimating];
[self performSelector:@selector(doCalcs) withObject:nil afterDelay:0];

This works well, except in the case where the code is run as a result of a message arriving over the network. I'm using http://code.google.com/p/cocoaasyncsocket/ to handle sockets and the code is running in the onSocket:didReadData:withTag: method.

'doCalcs' takes a few seconds. The spinner doesn't appear whilst it's running.

If I change afterDelay:0 to afterDelay:1 then the spinner does appear the whole time doCalcs is running, but with the downside that it takes an extra second. So it seems the code is all correct, but for whatever reason the spinner isn't getting a chance to get on screen before doCalcs runs.

Any suggestions would be most welcome.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk