Note that there are some explanatory texts on larger screens.

plurals
  1. POPerforming data intensive calculations during view init time
    primarykey
    data
    text
    <p>Folks,</p> <p>I'd like to get your opinions on the following scenario. Most screens on my app are table views where the number of rows and contents of the table view is determined by first reading data from the local core data tables and then performing some complex calculations on it. I'd like to do this in a way where the app does not freeze while the user is transitioning from one screen to another. Here is how I have done it. In the view did appear function I start animating an activity indicator and then spawn a thread to read data from the core data tables and perform all the relevant calculations on it. Inside this thread, upon completion of the calculations, I stop animating the activity indicator, mark a flag that initialization is complete and then reload the table view. Load of table view cells before the initialization is complete will return empty cells. (I noticed that the table view data source functions are called immediately after viewWillAppear and before ViewdidAppear()). Pasted below is my code:</p> <pre><code>-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"%s",__FUNCTION__); } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"%s",__FUNCTION__); [activityOutlet startAnimating]; dispatch_async(myQueue, ^{ [self getFromCoreData]; }); } - (void) getFromCoreData { // Get from coredata and start calculations here [activityOutlet stopAnimating]; activityOutlet.hidden = YES; [tableOutlet reloadData]; } </code></pre> <p>I'd like to know if there is a better way of doing the above.</p> <p>Thanks in advance for your responses!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload