ios - How to stop cellForItemAtIndexPath running if its datasource changed -
i collect photos alassetlibrary
, present them in uicollectionview
. add notification called alassetslibrarychangednotification
handle photo changes , call showlatestphotos whenever notification posted. photo-collection function like:
- (void)showlatestphotos { _latestphotos = [nsmutablearray array]; // photo asset , inset _latestphotos [_latestphotos insertobject:...]; [_collectionview reloaddata]; }
the problem if perform screenshot(click home , power @ same time), alassetslibrarychangednotification posted more twice, is, showlatestphtots executed twice, , second time when _latestphotos set empty using _latestphotos = [nsmutablearray array]
, cellforitematindexpath
of collectionview's
datasource triggered [_collectionview reloaddata]
in first call still being called , when call [_latestphotos objectatindex:],
application crashes. know how solve bug?
use work
if ([_latestphotos containsobject:yourobject] == no) { // _latestphotos = [nsmutablearray array]; // photo asset , inset _latestphotos [_latestphotos insertobject:...]; [_collectionview reloaddata]; }
Comments
Post a Comment