I want to stop开发者_开发百科 ActivityIndicator
after some time. I guess this can be achieved if I call a method after some time which stops activity indicator.
It can be achieved using NSTimer
, but I don't know how. An example with code snippet will be great.
In .h
class,
UIActivityIndicatorView *activity;
And used this code to your implementation class,
- (void)viewDidLoad {
[super viewDidLoad];
//initialise activityIndicator and add it to view
activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activity.frame = CGRectMake(150,200, 20, 20);
[self.view addSubview:activity];
[activity startAnimating];
//call timer to fire after your required time
[NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerMethod:) userInfo:nil repeats:NO];
}
Timer Action,
-(void) timerMethod : (NSTimer *) theTimer {
// after 1.5 seconds, the activity indicator will be hidden.
[activity stopAnimating];
}
精彩评论