ios - Reprinted Cell Text into an UITableViewCell -


into cellforrowatindexpath: method of uitableviewcontroller class using next code show cell contains uitextview.

sometimes when scroll table contains cell , scroll cell uitextview, shows cell text reprinted (as if there 2 uitextview objects, instead of one, cell).

what can solve problem?

static nsstring *cellidentifier = @"cell";  uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; }  cell.contentview.bounds = cgrectmake(0, 0, cell.frame.size.width, cell.frame.size.height); cell.selectionstyle = uitableviewcellselectionstylenone;  uitextview *textview = [[uitextview alloc] initwithframe:cell.contentview.bounds];                 textview.autoresizingmask = uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight; textview.editable = no; textview.scrollenabled = yes; textview.backgroundcolor = [uicolor clearcolor]; textview.font = [uifont fontwithname:@"helvetica" size:14.0]; textview.text = self.description;  [cell.contentview addsubview:textview]; [textview release]; 

uitableview reuses cells increase scrolling performance. whenever cell being reused, adding new text view cell (although 1 there).

you should move creation of text view (and adding cell) if (cell == nil) block. inside block, give text view unique tag , use tag property access text view outside block. see apple's table view sample code examples of pattern, being used lot.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -