iphone - iOS NSMutableArray sticking -
i'm trying populate uitableview
array contains files in directory
//in header @property (strong, nonatomic) nsmutablearray *files; //in tableview:cellforrow:atindexpath: static nsstring *cellid = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellid]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid]; cell.textlabel.text = [_files objectatindex:indexpath.row]; } return cell;
(_files
set equal [[nsfilemanager defaultmanager] contentsofdirectoryatpath:[self downloadsdir];
prior method being called) works, , shows correct files. problem if add file directory, , use tableview reloaddata
, new file added, title duplicate of file. example
table view before adding file
++++++++++++++++++++++++++ text.txt ++++++++++++++++++++++++++ testing.txt ++++++++++++++++++++++++++
table view after adding file othertest.txt
++++++++++++++++++++++++++ text.txt ++++++++++++++++++++++++++ testing.txt ++++++++++++++++++++++++++ testing.txt ++++++++++++++++++++++++++
it should be
++++++++++++++++++++++++++ text.txt ++++++++++++++++++++++++++ testing.txt ++++++++++++++++++++++++++ othertest.txt ++++++++++++++++++++++++++
if restart app, show correct files. reason this. know might wrong?
if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid]; cell.textlabel.text = [_files objectatindex:indexpath.row]; } return cell;
you're not setting cell label text except when allocate new cell. try instead:
if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid]; } cell.textlabel.text = [_files objectatindex:indexpath.row]; return cell;
same code, i've moved line set cell's text gets executed when reuse cell when create new one.
Comments
Post a Comment