In my firstViewController
there is a UIButton
(GalleryButton) and in my secondViewController
there is a UITableView
. When user taps the GalleryButton it takes 2-3 seconds time to open the secondViewController
and load the images. I want to show an UIActivityIndicator
until load the secondViewController
. How to do so??
Activity indicator until load the next view
3.8k views Asked by pigeon_39 At
3
There are 3 answers
0
On
Create Activity Indicator Programetically in your Second View Controller
var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
Add Below Code in viewDidLoad() of Second View Contoller
activityIndicator.hidesWhenStopped = true
activityIndicator.center = view.center
activityIndicator.startAnimating() //For Start Activity Indicator
When Data is Filled in Table View Completely than Add below code for stoping Activity Indicator
activityIndicator.stopAnimating() //For Stop Activity Indicator
0
On
this worked for me
#import "ViewController.h"
#import "NextVC.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *aiStart;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.aiStart.hidden = YES;
}
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
self.aiStart.hidden = YES;
[self.aiStart stopAnimating];
}
- (IBAction)btnShowNextVCTapped:(id)sender {
dispatch_async(dispatch_get_main_queue(), ^{
self.aiStart.alpha = 0;
self.aiStart.hidden = NO;
[self.aiStart startAnimating];
[UIView animateWithDuration:0.3 animations:^{
self.aiStart.alpha = 1;
} completion:^(BOOL finished) {
NextVC* nextVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NextVC"];
[self presentViewController:nextVC animated:YES completion:nil];
}];
});
}
You should load the images in a background thread and display the
UIActivityIndicator
in the main thread. I already replied to a similar issue here: https://stackoverflow.com/a/41529056/1370336