ios - How to use multiple reusable TableViewCells -


i add multiple reusable uitableviewcells tableview. using code this, won't work, shows first cell.

here code:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     if (indexpath.row == 0) {          static nsstring *costumecell1 = @"cell1";          appdetailcell1 *cell1 = [tableview dequeuereusablecellwithidentifier:costumecell1];          if (!cell1) {             cell1 = [[appdetailcell1 alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:costumecell1];         }          return cell1;     }     if (indexpath.row == 1) {          static nsstring *costumecell2 = @"cell2";          appdetailcell2 *cell2 = [tableview dequeuereusablecellwithidentifier:costumecell2];          if (!cell2) {             cell2 = [[appdetailcell2 alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:costumecell2];         }          return cell2;     } else {          return nil;      } } 

if set reuse identifiers properly, should change code part

appdetailcell1 *cell1 = [tableview dequeuereusablecellwithidentifier:costumecell1];

    if (!cell1) {         cell1 = [[appdetailcell1 alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:costumecell1];     } 

with this

appdetailcell1 *cell1 = [tableview dequeuereusablecellwithidentifier:costumecell1 forindexpath:indexpath]; 

there no need if(!cell1), because dequeuereusablecellwithidentifier: forindexpath: method never returns nil, said before reuse identifier set important.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -