Sorry but this may not be a programming question per se but more of an inquiry over the nature of iOS lifecycle functions.
I have an application where I have a function that creates four arrays and populates them via database queries. At first, I called the function from the viewDidLoad
function, however, whenever the View is loaded, it takes time (around 3-4 seconds) before the view actually appears. So what I did was I created an activityViewIndicator
and my viewDidLoad
function looks something like:
- (void)viewDidLoad:(BOOL)animated{
[super viewDidLoad];
NSLog(@"viewDidLoad Entered");
[self.activityIndicatorView startAnimating];
partInput.delegate = self;
brandInput.delegate = self;
barcodeInput.delegate = self;
itemNameInput.delegate = self;
//initializeArrays is the function that initializes the arrays
[self initializeArrays];
[self.activityIndicatorView stopAnimating];
}
However this doesn't work since the viewDidLoad
function is triggered when the application is still in the previous View. The View only comes into display after viewDidLoad
is already done. So what I did instead was move the array initialization to my viewDidAppear
function which looks like:
- (void)viewDidAppear:(BOOL)animated{
NSLog(@"viewDidAppear loaded successfully");
[self.activityIndicatorView startAnimating];
partInput.delegate = self;
brandInput.delegate = self;
barcodeInput.delegate = self;
itemNameInput.delegate = self;
[self initializeArrays];
[self.activityIndicatorView stopAnimating];
}
However, when I deployed this, there was no delay whatsoever, making the activityIndicatorView useless.
My question is, why does it seem to me that there's a "performance difference" between viewDidLoad
and viewDidAppear
?
initializeArrays
do the initialization in a separate thread? If it doesn't then you won't get the animation. – ReboundviewDidLoad
, and this leads to the delay. You can "lazy" load your VC withviewDidAppear
. This would allow you to do whatever at a time when background tasks are not going on. – Ehman