iphone - Stopping UITableViewCell reusability -


i know there bunch of questions here related topic couldn't find matches issue. have subclass of uitableviewcell named "customtableviewcell".

the below mentioned code works fine however, have check marks in cell , wanted stop reusability since max number of cells not exceed 25, hence no affect performance, guess after many searches, found out have either remove tableview dequeuereusablecellwithidentifier method or change identifier nil, unfortunately, empty cell when i that, , app crashes missing here?

this works fine reuses cell.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"customcell";      customtableviewcell *cell = (customtableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell = [[customtableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }      ...     ...     ...     ...      return cell; } 

while instead, code crashes:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"customcell";      customtableviewcell *cell = (customtableviewcell *)[tableview dequeuereusablecellwithidentifier:nil];     if (cell == nil) {         cell = [[customtableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }     ...     ...     return cell; } 

implement prepareforreuse

i recommend use reuse pattern, in opinion bad practice not it. guess real reason avoid use reuse pattern see 'old' state in custom cells when being reused.

to avoid this, should implement/override prepareforreuse method in custom cell, in method set custom properties default state.

in cellforrowatindexpath reuse cells , set custom properties values.

- (void)prepareforreuse() {     [super prepareforreuse];      //set custom properties default state     self.custom1 = ...;     self.custom2 = ...; } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -