iphone - UITableView Crashes -


hey everbody, i'm getting trouble here uitableview.

i'm setting uitableview create rows dynamically using xml. on iphone simulator works fine, when build on device, when drag table or down, app crashes.

something realized app crashes when row out of screen. so, when table still visible on screen, app works fine, when drag out of screen, crashes.

here goes code:

                #import "comentariosviewcontroller.h"                 #import "tbxml.h"                   @implementation comentariosviewcontroller                  @synthesize listacomentarios, tabelacomentarios, nomescomentarios, ratecomentarios;                   - (void)viewdidload                 {                    listacomentarios = [[nsmutablearray alloc] init];                  nomescomentarios = [[nsmutablearray alloc] init];                  ratecomentarios = [[nsmutablearray alloc] init];                   tbxml * tbxml = [[tbxml tbxmlwithurl:[nsurl                 urlwithstring:@"http://192.168.0.101/dev/mcomm/produto.xml"]] retain];                 tbxmlelement * rootxmlelement = tbxml.rootxmlelement;                  tbxmlelement * comentarios = [tbxml childelementnamed:@"comentarios" parentelement:rootxmlelement];                  tbxmlelement * comentario = [tbxml childelementnamed:@"comentario" parentelement:comentarios];                    while (comentario) {                    nsstring * desctext = [tbxml textforelement:comentario];                    nsstring * nome = [tbxml valueofattributenamed:@"nome" forelement:comentario];                    nsstring * rate = [tbxml valueofattributenamed:@"rate" forelement:comentario];                    [listacomentarios addobject:desctext];                   [nomescomentarios addobject:nome];                   [ratecomentarios addobject:rate];                    comentario = [tbxml nextsiblingnamed:@"comentario" searchfromelement:comentario];                    }                      tabelacomentarios.separatorstyle = uitableviewcellseparatorstylenone;                  tabelacomentarios.rowheight = 105;                  tabelacomentarios.backgroundcolor = [uicolor clearcolor];                    uiimageview *baloontop =                  [[[uiimageview alloc]                    initwithframe:                    cgrectmake(165, 25, 43, 29)]                   autorelease];               baloontop.image = [uiimage imagenamed:@"comentsbaloon.png"];                  // texto antes dos comentarios               uiview *containerview =              [[[uiview alloc]                initwithframe:cgrectmake(0, 0, 300, 70)]               autorelease];              uilabel *headerlabel =              [[[uilabel alloc]                initwithframe:cgrectmake(0, 20, 300, 40)]               autorelease];              headerlabel.text = nslocalizedstring(@"comentários", @"");              headerlabel.textcolor = [uicolor graycolor];              headerlabel.shadowcolor = [uicolor whitecolor];              headerlabel.shadowoffset = cgsizemake(1, 0);              headerlabel.font = [uifont boldsystemfontofsize:26];              headerlabel.backgroundcolor = [uicolor clearcolor];              [containerview addsubview:headerlabel];              [containerview addsubview:baloontop];              self.tabelacomentarios.tableheaderview = containerview;               [tbxml release];                  }                  // numero de secoes da tabela (essecial)                  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview                 {              return 1;                 }                  // numero de linhas da table (dinamico)                  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section                 {              return[listacomentarios count];                 }                  // criacao e montagem da tabela                  - (uitableviewcell *)tableview:(uitableview *)atableview cellforrowatindexpath:(nsindexpath *)indexpath                 {              const nsinteger top_label_tag = 1001;              uilabel *toplabel;              uitextview *bottomlabel;              uiimageview *ratebase;               static nsstring *cellidentifier = @"cell";              uitableviewcell *cell = [atableview dequeuereusablecellwithidentifier:cellidentifier];              if (cell == nil)              {               //               // create cell.               //               cell =               [[[uitableviewcell alloc]                 initwithframe:cgrectmake(0, 0, 180, 200)                 reuseidentifier:cellidentifier]                autorelease];                 //               // create label top row of text               //               toplabel =               [[[uilabel alloc]                 initwithframe:                 cgrectmake(10, 5, 200, 20)]                autorelease];                toplabel.font = [uifont boldsystemfontofsize:15];               toplabel.textcolor = [uicolor graycolor];                [cell.contentview addsubview:toplabel];                 // rates                ratebase =               [[[uiimageview alloc]                 initwithframe:                 cgrectmake(215, 10, 67, 10)]                autorelease];                nsstring *ratevalue = [ratecomentarios objectatindex:indexpath.row];                nsstring *rateimage = [[nsstring alloc] initwithformat:@"rate%@.png",ratevalue];                ratebase.image = [uiimage imagenamed:rateimage];                [cell.contentview addsubview:ratebase];                // top baloon                   //               // configure properties text same on every row               //                 //               // create label top row of text               //               bottomlabel = [[[uitextview alloc] initwithframe: cgrectmake(2, 28, 270, 58)] autorelease];               [cell.contentview addsubview:bottomlabel];                bottomlabel.editable = no;               bottomlabel.scrollenabled = no;                //               // configure properties text same on every row               //               nsstring *cellvalue =[listacomentarios objectatindex:indexpath.row];               bottomlabel.text = cellvalue;                bottomlabel.backgroundcolor = [uicolor clearcolor];               bottomlabel.textcolor = [uicolor colorwithred:0.25 green:0.0 blue:0.0 alpha:1.0];               //bottomlabel.highlightedtextcolor = [uicolor colorwithred:1.0 green:1.0 blue:0.9 alpha:1.0];               bottomlabel.font = [uifont systemfontofsize:13];                //               // create background image view.               //               cell.backgroundview =               [[[uiimageview alloc] init] autorelease];               cell.selectedbackgroundview =               [[[uiimageview alloc] init] autorelease];              }               else              {               toplabel = (uilabel *)[cell viewwithtag:top_label_tag];               //bottomlabel = (uilabel *)[cell viewwithtag:bottom_label_tag];              }               nsstring *qlnome = [nomescomentarios objectatindex:indexpath.row];              toplabel.text = qlnome;               nsstring *cellvalue =[listacomentarios objectatindex:indexpath.row];              bottomlabel.text = cellvalue;                      //              // set background , selected background images text.              // since round corners @ top , bottom of sections,              // need conditionally choose images based on row index ,              // number of rows in section.              //              uiimage *rowbackground;              //uiimage *selectionbackground;              rowbackground = [uiimage imagenamed:@"comentariosbaloon.png"];              //selectionbackground = [uiimage imagenamed:@"bkgcomentarios.png"];              ((uiimageview *)cell.backgroundview).image = rowbackground;              //((uiimageview *)cell.selectedbackgroundview).image = selectionbackground;                return cell;                 }                   - (void)dealloc                 {              [tabelacomentarios release];              [tbxml release];               [super dealloc];                 }                   @end 

thanks help!

in case cell dequeued tableview, neglect set pointer bottomlabel particular value , subsequently implicitly dereference it. if genuinely don't want point when cell dequeued initialise pointing nil:

uitextview *bottomlabel = nil; 

it's safe message nil in objective-c.

you've commented out line:

//bottomlabel = (uilabel *)[cell viewwithtag:bottom_label_tag]; 

without knowing wider context of program, guess possible commenting out error. if want set value of bottomlabel when cell dequeued, want reinstate that.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -