iphone - TableView mix up the cells -
i have tableview static cells header has 4 cells, 1 cell in middle carries uiwebview , footer section comments. each comment has it's own cell. problem if footer has 4 or more comments, 4th cell in footer carries same uiwebview cell in middle.
my cellforrowatindexpath looks this:
// customize appearance of table view cells. - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { // cell static nsstring *cellidentifier = @"cella"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; cell.selectionstyle = uitableviewcellselectionstylenone; } uitableviewcell *contentcell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (contentcell == nil) { contentcell = [[customdetailtableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } // display cell.textlabel.textcolor = [uicolor blackcolor]; cell.textlabel.font = [uifont systemfontofsize:15]; if (item) { // item info nsstring *itemtitle = item.title ? [item.title stringbyconvertinghtmltoplaintext] : @"[no title]"; // display switch (indexpath.section) { case sectionheader: { // header switch (indexpath.row) { case sectionheadertitle: cell.textlabel.font = [uifont boldsystemfontofsize:15]; cell.textlabel.text = itemtitle; cell.textlabel.numberoflines = 0; // multiline break; case sectionheaderdate: cell.textlabel.text = datestring ? datestring : @"[kein datum]"; cell.imageview.image = nil; break; case sectionheadersharerfacebook: cell.textlabel.text = @"share on facebook"; cell.imageview.image = [uiimage imagenamed:@"f_logo.png"]; break; case sectionheadersharertwitter: cell.textlabel.text = @"share on twitter"; cell.imageview.image = [uiimage imagenamed:@"twitter-bird-blue-on-white.png"]; } break; } case sectiondetail: { //add webview cell if (webviewdidfinishload == true && indexpath.section != sectioncomments) { cgfloat contentheight = webview.scrollview.contentsize.height; webview.frame = cgrectmake(23, 10, 275, contentheight); } else { webview.frame = cgrectmake(23, 10, 275, 10); } cell.backgroundcolor = [uicolor whitecolor]; [cell addsubview:webview]; break; } case sectioncomments: { nsstring *writertext = [[[self.commentparser.commentsarray objectatindex:indexpath.row] name] stringbyappendingstring:@" schrieb:\n"]; writertext = [writertext stringbyappendingstring:[[self.commentparser.commentsarray objectatindex:indexpath.row] description]]; writertext = [writertext stringbyappendingformat:@"\n"]; cell.textlabel.text = writertext; cell.imageview.image = nil; cell.textlabel.linebreakmode = uilinebreakmodewordwrap; cell.textlabel.numberoflines = 0; //multiline if (cell.textlabel.text == nil) { cell.textlabel.text = @"keine kommentare vorhanden"; cell.textlabel.font = [uifont fontwithname:@"verdana-italic" size:12]; } break; } } return cell; } }
why uiwebview in 4th cell again, , how can change ?
thanks every answer!
the reason uitableview
reuses it's cells conserve memory. there tons of questions on topic, recommend read (1, 2, ...). briefly, when do:
uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];
for cell in footer section, cell in middle section contains uiwebview
. need remove uiwebview
subview before reuse cell in footer section.
Comments
Post a Comment