ios - UICollectionView very slow to load because of dequeueWithReusableIdentifier, can I load it in background? -
i'm facing issue reaaaally don't find answer to. have collectionview, , every time tap button, reloaddata of collectionview new parameters. problem takes around 1-2s wich annoying , freeze ui.
i know if there way reload collectionview in background , diplay when it's done, (in pseudo-code) :
self.collectionview.hidden = yes; dispatch_async({ [self.collectionview reloaddata]; });
and when it's updated :
self.collectionview.hidden = no;
i haven't found how on internet, , need help.
full code cellforrowatindexpath method :
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *cell = nil; if (indexpath.row >= 1 && indexpath.row <= 7) { static nsstring *cellidentifier = @"agzdaylettercell"; cell =(agzdaylettercollectionviewcell*)[collectionview dequeuereusablecellwithreuseidentifier:cellidentifier forindexpath:indexpath]; ((agzdaylettercollectionviewcell*)cell).dayfirstletterlabel.text = [self.daysfirstletterarray objectatindex:(indexpath.row-1)]; cell.userinteractionenabled = no; } else if (indexpath.row%8 == 0) { static nsstring *cellidentifier = @"agzseparatorcell"; cell = [collectionview dequeuereusablecellwithreuseidentifier:cellidentifier forindexpath:indexpath]; cell.userinteractionenabled = no; } else if (indexpath.row > 8+self.delay) { nsstring *daynumbertapped = [nsstring stringwithformat:@"%ld", (long)indexpath.row-7-(int)indexpath.row/8-self.delay]; static nsstring *cellidentifier = @"agzdaycell"; cell =(agzdaycollectionviewcell*)[collectionview dequeuereusablecellwithreuseidentifier:cellidentifier forindexpath:indexpath]; ((agzdaycollectionviewcell*)cell).datetappedstring = [self getdatestringfordaynumber:daynumbertapped]; nsdate *selecteddaydate = [[self getdatestringfordaynumber:daynumbertapped] datefromstringforrfc3339format]; ((agzdaycollectionviewcell*)cell).dayappointmentsarray = (nsmutablearray*)[self.appointmentsdictionary objectforkey:[selecteddaydate getdateonlyrfc3339format]]; // check if cell today's date , set design according result if ([[self.viewdate getdateonly] isequaltostring:[[nsdate date] getdateonly]] && [[nsdate date] getday] == [daynumbertapped intvalue]) ((agzdaycollectionviewcell*)cell).istodayday = yes; else ((agzdaycollectionviewcell*)cell).istodayday = no; } else { static nsstring *cellidentifier = @"agzdaycell"; cell =(agzdaycollectionviewcell*)[collectionview dequeuereusablecellwithreuseidentifier:cellidentifier forindexpath:indexpath]; ((agzdaycollectionviewcell*)cell).datetappedstring = @""; cell.userinteractionenabled = no; ((agzdaycollectionviewcell*)cell).istodayday = no; } return cell; }
i think it's unlikely issue collection view. many people using them in sorts of ways far better performance getting. what's more whatever code generating data taking time. example - hitting server. that's code should on ground thread call or completion block attached.
ui code should never on background 3 , cause sorts of ui issues if not run on main thread.
Comments
Post a Comment