Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3455046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:33:57+00:00 2026-05-18T09:33:57+00:00

Hey everbody, i’m getting some trouble here with the UITableView. I’m setting my UITableView

  • 0

Hey everbody, i’m getting some trouble here with the UITableView.

I’m setting my UITableView to create the rows dynamically using a XML. On iPhone Simulator everything works fine, but when i just build it on device, when i drag the table to up or down, the app crashes.

Something what i realized is that app just crashes when some row get out of the screen. So, when the table still visible on screen, the app works fine, but when i drag it out of screen, crashes.

Here goes the 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 the cell.
              //
              cell =
              [[[UITableViewCell alloc]
                initWithFrame:CGRectMake(0, 0, 180, 200)
                reuseIdentifier:CellIdentifier]
               autorelease];


              //
              // Create the label for the 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 the properties for the text that are the same on every row
              //


              //
              // Create the label for the 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 the properties for the text that are the 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 a 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 the background and selected background images for the text.
             // Since we will round the corners at the top and bottom of sections, we
             // need to conditionally choose the images based on the row index and the
             // number of rows in the 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 for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:33:58+00:00Added an answer on May 18, 2026 at 9:33 am

    In the case where a cell is successfully dequeued from the tableview, you neglect to set the pointer bottomLabel to any particular value and subsequently implicitly dereference it. If you genuinely don’t want it to point to anything when a cell is dequeued then initialise it as pointing to nil:

    UITextView *bottomLabel = nil;
    

    It’s always safe to message nil in Objective-C.

    You’ve commented out the line:

    //bottomLabel = (UILabel *)[cell viewWithTag:BOTTOM_LABEL_TAG];
    

    Without knowing the wider context of your program, I guess it is also possible that this commenting out is an error. If you do want to set the value of bottomLabel when a cell is dequeued, you probably want to reinstate that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everbody, im getting some trouble here. When my viewcontroller reaches the view, it
Hey everbody, im getting some trouble here. Well, im trying to pass a value
Hey having some trouble trying to maintain transparency on a png when i create
Hey everbody, im getting a curious problem here. Im trying to make my table
Hey right now I'm using jQuery and I have some global variables to hold
Hey everbody. I have a little issue here. I just want to scale my
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey, in the Programming Pearls book, there is a source code for setting, clearing
Hey guys. I'm not much of a programmer, but still need to do some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.