我想只在动作花费太多时间时启动我的UIActivityIndicator:
- (void) continueLaunch {
//operations
//.....
[activityIndic stopAnimating];
}
//my current method
- (void)lauchApplication {
[activityIndic startAnimating];
[self performSelector:@selector(continueLaunch) withObject:nil afterDelay:0.0f];
}
//what I want to do
- (void)lauchApplication {
if ([self performSelector:@selector(continueLaunch) withObject:nil afterDelay:0.0f]duration > 1 second){
[activityIndic startAnimating];
}
}
我该怎么做?
答案 0 :(得分:5)
我认为最好的方法是在您想要等待的持续时间之后启动指标,如果在该持续时间之前的某个时刻发生了某些事情,您可以取消它:
[self performSelector:@selector(startAnimation) withObject:nil afterDelay:1.0f]
取消它(来自Apple Doc):
要取消排队的消息,请使用 cancelPreviousPerformRequestsWithTarget:或 cancelPreviousPerformRequestsWithTarget:selector:object:method。
答案 1 :(得分:2)
一种可能的解决方案是: