Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the correct way to reload data in a UICollectionView?
    primarykey
    data
    text
    <p>If I am getting information from an album in the users assetslibrary and they add a picture or remove on from it while my app is in the background. Whats the best way to reload them.</p> <p>Currently I have:</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(assetsLibraryDidChange:) name:ALAssetsLibraryChangedNotification object:_photoListArray]; </code></pre> <p>To get the initial notification and then it calls my assetLibraryDidChange method:</p> <p>Which looked like this:</p> <pre><code>- (void)assetsLibraryDidChange:(NSNotification *)note { //dict nil reload if(note.userInfo==nil) { [self.CoverView reloadData]; return; } //dict empty no reload if(note.userInfo.count == 0) { NSLog(@"empty"); return; } else { [self.CoverView reloadData]; } } </code></pre> <p>Although I am considering removing all the if's and else and just having it reload every time. </p> <hr> <p>What I'm getting to:</p> <p>There seems to be a gap between when my app receives the notification and it actually updates. Apple's default photos app seems to be able to do it in around 3-4 seconds while it takes mine almost 10!. Is there a more efficient way to do this?</p> <hr> <p>I went ahead and put a nslog before all the if's to see how many times the method was being called as well.</p> <pre><code>//Library Updated - (void)assetsLibraryDidChange:(NSNotification *)note { NSLog(@"photos updated"); //dict nil reload if(note.userInfo==nil) { dispatch_async(dispatch_get_main_queue(), ^{ [self.CoverView reloadData]; NSLog(@"note: %@", note.userInfo); NSLog(@"array: %@", _photoListArray); return; }); } //dict empty no reload if(note.userInfo.count == 0) { NSLog(@"empty"); return; } else { dispatch_async(dispatch_get_main_queue(), ^{ [self.CoverView reloadData]; NSLog(@"note2: %@", note.userInfo); NSLog(@"array2: %@", _photoListArray); }); } } </code></pre> <p>And they resulted in the following:</p> <pre><code>2013-08-16 10:41:51.622 app[180:1803] photos updated 2013-08-16 10:41:51.635 app[180:60b] note2: { ALAssetLibraryUpdatedAssetsKey = "{(\n assets-library://asset/asset.JPG?id=CCA17BE2-5633-4FFE-A113-F21E37B9882C&amp;ext=JPG,\n assets-library://asset/asset.JPG?id=7B05283E-87A5-4CFE-BDBE-7703E311E0DF&amp;ext=JPG,\n assets-library://asset/asset.JPG?id=5B1E736F-E21E-4400-9679-5DE8215AC09D&amp;ext=JPG\n)}"; } 2013-08-16 10:41:51.638 app[180:60b] array2: ( "&lt;Media: 0x176b3410&gt;", "&lt;Media: 0x176b5b00&gt;", "&lt;Media: 0x176b5c90&gt;", "&lt;Media: 0x176b7590&gt;", "&lt;Media: 0x176b47c0&gt;", "&lt;Media: 0x176b7e10&gt;", "&lt;Media: 0x176b83b0&gt;", "&lt;Media: 0x176b8990&gt;", "&lt;Media: 0x176b8f40&gt;", "&lt;Media: 0x176b9530&gt;", "&lt;Media: 0x176ba160&gt;", "&lt;Media: 0x176ba960&gt;", "&lt;Media: 0x175794d0&gt;", "&lt;Media: 0x175503c0&gt;", "&lt;Media: 0x17571f80&gt;", "&lt;Media: 0x1756dc20&gt;", "&lt;Media: 0x17571060&gt;", "&lt;Media: 0x1757b0d0&gt;", "&lt;Media: 0x1757b8f0&gt;", "&lt;Media: 0x1757bee0&gt;", "&lt;Media: 0x1757bcf0&gt;", "&lt;Media: 0x1757ca80&gt;", "&lt;Media: 0x1757cbd0&gt;" ) 2013-08-16 10:41:51.827 app[180:3e07] photos updated 2013-08-16 10:41:51.831 app[180:3e07] empty 2013-08-16 10:41:51.893 app[180:3e07] photos updated 2013-08-16 10:41:51.897 app[180:3e07] empty 2013-08-16 10:41:52.059 app[180:3e07] photos updated 2013-08-16 10:41:52.074 app[180:3e07] empty 2013-08-16 10:41:52.092 app[180:5117] photos updated 2013-08-16 10:41:52.095 app[180:5117] empty </code></pre> <p>The Media objects are a class which I am just using to add data and have it stored along with them. Name, ext. Nothing that changes the actual image.</p> <p>Without the dispatch:</p> <pre><code>2013-08-16 11:37:53.246 app[296:3d07] photos updated 2013-08-16 11:37:53.255 app[296:3d07] note2: { ALAssetLibraryUpdatedAssetsKey = "{(\n assets-library://asset/asset.JPG?id=CCA17BE2-5633-4FFE-A113-F21E37B9882C&amp;ext=JPG,\n assets-library://asset/asset.PNG?id=D72A00CE-4198-45BE-BCC5-8DEB8419A5C8&amp;ext=PNG,\n assets-library://asset/asset.JPG?id=5B1E736F-E21E-4400-9679-5DE8215AC09D&amp;ext=JPG\n)}"; } 2013-08-16 11:37:53.260 app[296:3d07] array2: ( "&lt;Media: 0x176271b0&gt;", "&lt;Media: 0x17577920&gt;", "&lt;Media: 0x17579c50&gt;", "&lt;Media: 0x17579eb0&gt;", "&lt;Media: 0x17579e00&gt;", "&lt;Media: 0x1757a9b0&gt;", "&lt;Media: 0x1757af50&gt;", "&lt;Media: 0x1757b540&gt;", "&lt;Media: 0x1757baf0&gt;", "&lt;Media: 0x1757c0e0&gt;", "&lt;Media: 0x17656510&gt;", "&lt;Media: 0x176570f0&gt;", "&lt;Media: 0x176572b0&gt;", "&lt;Media: 0x17657840&gt;", "&lt;Media: 0x17657e20&gt;", "&lt;Media: 0x17658400&gt;", "&lt;Media: 0x176589e0&gt;", "&lt;Media: 0x17659270&gt;", "&lt;Media: 0x17650470&gt;", "&lt;Media: 0x17659380&gt;", "&lt;Media: 0x176507a0&gt;", "&lt;Media: 0x17650ab0&gt;", "&lt;Media: 0x17659cb0&gt;", "&lt;Media: 0x1765a340&gt;" ) 2013-08-16 11:37:53.404 app[296:4e17] photos updated 2013-08-16 11:37:53.408 app[296:4e17] empty 2013-08-16 11:37:53.450 app[296:3d07] photos updated 2013-08-16 11:37:53.458 app[296:3d07] empty 2013-08-16 11:37:53.466 app[296:4e17] photos updated 2013-08-16 11:37:53.470 app[296:4e17] empty </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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