Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity indicator for 5seconds?

All

I am trying to run UIActivityIndicator for a 5 seconds on viewdidappear method .But how do i give a time limit for activity indicator(5 seconds) ?

This is the code for UIActivityIndicator

 UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc]     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    activityView.center=self.view.center;

    [activityView startAnimating];

    [self.view addSubview:activityView];
like image 539
Navi Avatar asked Jan 14 '23 06:01

Navi


2 Answers

With one line and no additional dependencies & conditions:

[activityView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:5.0];
like image 65
Alexander Avatar answered Jan 23 '23 04:01

Alexander


Set activity view to hide automatically when stopped

activityView.hidesWhenStopped = YES;

And hide it after 5s like this:

[activityView performSelector:@selector(stopAnimating) withObject:nil afterDelay:5.0];

This will allow you to start animation again by just calling startAnimating if you need so in the future and keep pointer to the UIActivityIndicatorView

If you just need to show activity indicator once and will not use it anymore, Alexanders answer will suit best to your needs

like image 41
Lukas Kukacka Avatar answered Jan 23 '23 02:01

Lukas Kukacka