当需要很长时间才能执行某些操作时,使用UIActivityIndi​​catorView显示UIView

时间:2011-08-23 10:32:32

标签: iphone ios

我有一些代码来处理大尺寸文件,这需要很长时间。 我希望在进度开始时使用UIActivityIndi​​catorView显示视图,并在完成时隐藏视图

以下代码

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

[self dosomething];//take a long time                   

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

但其执行顺序为:

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

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

[self dosomething];//take a long time       

所以没有任何显示

欢迎任何评论

1 个答案:

答案 0 :(得分:0)

为什么不使用线程?在方法dosomething中启动指标,然后停止该指标

在main方法中启动指标并替换

[self dosomething];

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

并停止您的活动