开发者

display UIView with UIActivityIndicatorView when it takes a long time to do something

I have some codes to process a large size file, it will take a long time. I hop开发者_Python百科e to display a view with UIActivityIndicatorView when the progress starts and hide the view when it completed

The code as below

[[NSNotificationCenter defaultCenter] postNotificationName:@"DisplayProcessing" object:nil];

[self dosomething];//take a long time                   

[[NSNotificationCenter defaultCenter] postNotificationName:@"HideProcessing" object:nil];

but its excution order is:

[[NSNotificationCenter defaultCenter] postNotificationName:@"DisplayProcessing" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"HideProcessing" object:nil];

[self dosomething];//take a long time       

so there is nothing display

Welcome any comment


why dont you use thread? start your indicator in method dosomething and then stop that indicator

start indicator in main method and replace

[self dosomething];

with

[self performSelectorOnMainThread:@selector(dosomething:) withObject:nil waitUntilDone:NO];

and stop your activity here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜