开发者

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

开发者 https://www.devze.com 2023-03-29 21:00 出处:网络
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 comp

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

精彩评论

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