UITableView issue (iOS) -
i wonder why cellforrowatindexpath
function called when scrolling uitableview. mean on every scrolling cell configuration code runs again? have slowness problem when scrolling table.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"countrycell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; } // configure cell... nsstring *continent = [self tableview:tableview titleforheaderinsection:indexpath.section]; nsstring *country = [[self.countries valueforkey:continent] objectatindex:indexpath.row]; cell.textlabel.text = country; cell.accessorytype = uitableviewcellaccessorydisclosureindicator; return cell; }
as others have said, yes, when each new cell scroll onto screen, cellforrowatindexpath
called each cell. while may strike performance hit, alternative (for ios create of cells up-front) worse: if you're finding slow create 1 cell, imagine having create hundreds, many of user may never see. anyway, just-in-time nature of cellforrowatindexpath
more efficient, both in terms of up-front performance hit, in terms of precious memory consumption on small mobile device.
in terms of slow performance, there's nothing here culprit. lot of have cellforrowatindexpath
methods more complicated , speed not issue. maybe there more efficient alternatives valueforkey
lookup might advise if doing millions of lookups, 1 cell difference not observable human eye. think have elsewhere. titleforheaderinsection
doing strange (i.e. other looking value in array)? maybe can share us. maybe in ui. maybe should run through profiler's "time profiler" , maybe stick out. cellforrowatindexpath
simple should result in smooth user experience.
Comments
Post a Comment