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 9158457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:15:02+00:00 2026-06-17T13:15:02+00:00

What I am trying to do is taking the static data and show the

  • 0

What I am trying to do is taking the static data and show the data in UITableView. Below is what I have.

Note: : I am adding label and imageView in cell programatically as I have english and arabic version app.

//
//  ListViewController.m
//  Demo
//
//  Created by  on 1/20/13.
//  Copyright (c) 2013 . All rights reserved.
//

#import "ListViewController.h"
#import "ListOfProperty.h"
#import "Localization.h"
#import <QuartzCore/QuartzCore.h>

@interface ListViewController ()

@end

@implementation ListViewController {
    NSMutableArray *propListFinal;
}

@synthesize headerLabel, secondImage, myTableView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void) viewWillAppear:(BOOL)animated {

    NSLog(@"in viewWillAppear");

    secondImage.alpha = 0.4f;

    propListFinal = [[NSMutableArray alloc] initWithCapacity:2];

    ListOfProperty *listOfProperty;

    listOfProperty = [[ListOfProperty alloc] init];
    listOfProperty.refIDOfFlat = @"8756342";
    listOfProperty.addressOfFlat = @"Al Salam, Hawalli, Kuwait";
    listOfProperty.amountOfFlat = @"2500";
    listOfProperty.typeOfFlat = @"Villa";
    listOfProperty.areaOfFlat = @"300";
    listOfProperty.imageName = @"home0.jpg";
    [propListFinal addObject:listOfProperty];

    listOfProperty = [[ListOfProperty alloc] init];
    listOfProperty.refIDOfFlat = @"6342875";
    listOfProperty.addressOfFlat = @"Al Salam, Khaitan, Kuwait";
    listOfProperty.amountOfFlat = @"2300";
    listOfProperty.typeOfFlat = @"Villa";
    listOfProperty.areaOfFlat = @"400";
    listOfProperty.imageName = @"home1.jpg";
    [propListFinal addObject:listOfProperty];

    listOfProperty = [[ListOfProperty alloc] init];
    listOfProperty.refIDOfFlat = @"8573624";
    listOfProperty.addressOfFlat = @"Hateen, Hawalli, Kuwait";
    listOfProperty.amountOfFlat = @"1500";
    listOfProperty.typeOfFlat = @"House";
    listOfProperty.areaOfFlat = @"415";
    listOfProperty.imageName = @"home2.jpg";
    [propListFinal addObject:listOfProperty];

    listOfProperty = [[ListOfProperty alloc] init];
    listOfProperty.refIDOfFlat = @"8634752";
    listOfProperty.addressOfFlat = @"Hateen, Salmiya, Kuwait";
    listOfProperty.amountOfFlat = @"1300";
    listOfProperty.typeOfFlat = @"Flat";
    listOfProperty.areaOfFlat = @"325";
    listOfProperty.imageName = @"home3.jpg";
    [propListFinal addObject:listOfProperty];

    listOfProperty = [[ListOfProperty alloc] init];
    listOfProperty.refIDOfFlat = @"8427563";
    listOfProperty.addressOfFlat = @"Al Salam, Jaleeb, Kuwait";
    listOfProperty.amountOfFlat = @"2500";
    listOfProperty.typeOfFlat = @"Small Flat";
    listOfProperty.areaOfFlat = @"100";
    listOfProperty.imageName = @"home4.jpg";
    [propListFinal addObject:listOfProperty];

    listOfProperty = [[ListOfProperty alloc] init];
    listOfProperty.refIDOfFlat = @"8427561";
    listOfProperty.addressOfFlat = @"Al Salam, Mallya, Kuwait";
    listOfProperty.amountOfFlat = @"2500";
    listOfProperty.typeOfFlat = @"Small Flat";
    listOfProperty.areaOfFlat = @"100";
    listOfProperty.imageName = @"home5.jpg";
    [propListFinal addObject:listOfProperty];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (int)numberOfSectionsInTableView:(UITableView *) tableView {
    return 1;
}

- (int) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section {
    return [propListFinal count];
}

-(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"];
    }

    NSString *commString;

    NSString *myLanguage = localize(@"myLanguage");

    ListOfProperty *propList = [propListFinal objectAtIndex:indexPath.row];

    UIImageView *myImageview;
    UILabel *addressLabel;
    UILabel *typeLabel;
    UILabel *areaLabel;
    UILabel *priceLabel;

    if ([myLanguage isEqualToString:@"en"]) {
        myImageview = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 75, 65)];
        addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(87, 9, 223, 21)];
        typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(87, 32, 223, 21)];
        areaLabel = [[UILabel alloc] initWithFrame:CGRectMake(87, 55, 223, 21)];
        priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(4, 74, 110, 21)];
    } else {
        myImageview = [[UIImageView alloc] initWithFrame:CGRectMake(240, 004, 75, 65)];
        addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(11, 9, 223, 21)];
        typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(11, 32, 223, 21)];
        areaLabel = [[UILabel alloc] initWithFrame:CGRectMake(11, 55, 223, 21)];
        priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 74, 110, 21)];
        addressLabel.textAlignment = NSTextAlignmentRight;
        typeLabel.textAlignment = NSTextAlignmentRight;
        areaLabel.textAlignment = NSTextAlignmentRight;
        priceLabel.textAlignment = NSTextAlignmentRight;
    }

    [addressLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 13.0]];
    [typeLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 13.0]];
    [areaLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 13.0]];
    [priceLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 15.0]];
    [priceLabel setFont:[UIFont boldSystemFontOfSize:15.0]];


    addressLabel.backgroundColor = [UIColor clearColor];
    typeLabel.backgroundColor = [UIColor clearColor];
    areaLabel.backgroundColor = [UIColor clearColor];
    priceLabel.backgroundColor = [UIColor clearColor];

    addressLabel.textColor = [UIColor colorWithRed:(246/255.0) green:(230/255.0) blue:(74/255.0) alpha:1.0f];
    typeLabel.textColor = [UIColor colorWithRed:(246/255.0) green:(230/255.0) blue:(74/255.0) alpha:1.0f];
    areaLabel.textColor = [UIColor colorWithRed:(246/255.0) green:(230/255.0) blue:(74/255.0) alpha:1.0f];
    priceLabel.textColor = [UIColor colorWithRed:(26/255.0) green:(169/255.0) blue:(213/255.0) alpha:1.0f];

    commString = [NSString stringWithFormat:@"Ref. ID : %@", propList.refIDOfFlat];
    addressLabel.text = propList.addressOfFlat;
    NSLog(@"data is %@", propList.addressOfFlat);
    typeLabel.text = propList.typeOfFlat;
    commString = [NSString stringWithFormat:@"%@ Sq. Meter.", propList.areaOfFlat];
    areaLabel.text = commString;
    commString = [NSString stringWithFormat:@"%@ KWD", propList.amountOfFlat];
    priceLabel.text = commString;

    myImageview.image = [UIImage imageNamed:propList.imageName];

    [cell.contentView  addSubview:myImageview];
    [myImageview release];

    [cell.contentView  addSubview:addressLabel];
    [addressLabel release];

    [cell.contentView  addSubview:typeLabel];
    [typeLabel release];

    [cell.contentView  addSubview:areaLabel];
    [areaLabel release];

    [cell.contentView  addSubview:priceLabel];
    [priceLabel release];

    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return NO;
}

- (void)dealloc {
    [headerLabel release];
    [secondImage release];
    [myTableView release];
    [super dealloc];
}
@end

Now when I run the app, I have below screen which is fine.

as I don’t have right to upload image, I am providing link

Image 1

Now when I scroll down, I have this screen.

Image 2

When you look at last row, the text are mixed. 🙁 I don’t get why this is happening?

Now when I scroll up, again the text is mixed as shown in below image.

Image 3

i.e. on one label I see two text

Now I added one more entry of building and below is what I get after scrolling the tableView up and down.

Image 4

i.e. on one label I see two text

My question would be, why this is happening in this case?

  • 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-06-17T13:15:03+00:00Added an answer on June 17, 2026 at 1:15 pm

    From what i see from your code, you are reusing the previous cell but alloc/initing all labels and image views every time, which is not a good approach and causing all this problem.

    You shouldn’t create these subviews every time just create two cells with different identifiers and later just assign them updated values like this:

    -(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *commString;
    
    NSString *myLanguage = localize(@"myLanguage");
    
    UIImageView *myImageview;
    UILabel *addressLabel;
    UILabel *typeLabel;
    UILabel *areaLabel;
    UILabel *priceLabel;
    
    NSString *cellIdentifier = [myLanguage isEqualToString:@"en"]?@"EngCell":@"ARCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    
        if ([myLanguage isEqualToString:@"en"]) {
            myImageview = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 75, 65)];
            addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(87, 9, 223, 21)];
            typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(87, 32, 223, 21)];
            areaLabel = [[UILabel alloc] initWithFrame:CGRectMake(87, 55, 223, 21)];
            priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(4, 74, 110, 21)];
        } else {
            myImageview = [[UIImageView alloc] initWithFrame:CGRectMake(240, 004, 75, 65)];
            addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(11, 9, 223, 21)];
            typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(11, 32, 223, 21)];
            areaLabel = [[UILabel alloc] initWithFrame:CGRectMake(11, 55, 223, 21)];
            priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 74, 110, 21)];
            addressLabel.textAlignment = NSTextAlignmentRight;
            typeLabel.textAlignment = NSTextAlignmentRight;
            areaLabel.textAlignment = NSTextAlignmentRight;
            priceLabel.textAlignment = NSTextAlignmentRight;
        }
    
        [addressLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 13.0]];
        [typeLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 13.0]];
        [areaLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 13.0]];
        [priceLabel setFont:[UIFont fontWithName:localize(@"myFont") size: 15.0]];
        [priceLabel setFont:[UIFont boldSystemFontOfSize:15.0]];
    
    
        addressLabel.backgroundColor = [UIColor clearColor];
        typeLabel.backgroundColor = [UIColor clearColor];
        areaLabel.backgroundColor = [UIColor clearColor];
        priceLabel.backgroundColor = [UIColor clearColor];
    
        myImageview.tag = 10;
        addressLabel.tag = 11;
        typeLabel.tag = 12;
        areaLabel.tag = 13;
        priceLabel.tag = 14;
    
        addressLabel.textColor = [UIColor colorWithRed:(246/255.0) green:(230/255.0) blue:(74/255.0) alpha:1.0f];
        typeLabel.textColor = [UIColor colorWithRed:(246/255.0) green:(230/255.0) blue:(74/255.0) alpha:1.0f];
        areaLabel.textColor = [UIColor colorWithRed:(246/255.0) green:(230/255.0) blue:(74/255.0) alpha:1.0f];
        priceLabel.textColor = [UIColor colorWithRed:(26/255.0) green:(169/255.0) blue:(213/255.0) alpha:1.0f];
    
        [cell.contentView  addSubview:myImageview];
        [myImageview release];
    
        [cell.contentView  addSubview:addressLabel];
        [addressLabel release];
    
        [cell.contentView  addSubview:typeLabel];
        [typeLabel release];
    
        [cell.contentView  addSubview:areaLabel];
        [areaLabel release];
    
        [cell.contentView  addSubview:priceLabel];
        [priceLabel release];
    }
    
    myImageview = [cell viewWithTag:10];
    addressLabel = [cell viewWithTag:11];
    typeLabel = [cell viewWithTag:12];
    areaLabel = [cell viewWithTag:13];
    priceLabel = [cell viewWithTag:14];
    
    ListOfProperty *propList = [propListFinal objectAtIndex:indexPath.row];
    
    commString = [NSString stringWithFormat:@"Ref. ID : %@", propList.refIDOfFlat];
    addressLabel.text = propList.addressOfFlat;
    NSLog(@"data is %@", propList.addressOfFlat);
    typeLabel.text = propList.typeOfFlat;
    commString = [NSString stringWithFormat:@"%@ Sq. Meter.", propList.areaOfFlat];
    areaLabel.text = commString;
    commString = [NSString stringWithFormat:@"%@ KWD", propList.amountOfFlat];
    priceLabel.text = commString;
    
    myImageview.image = [UIImage imageNamed:propList.imageName];
    
    return cell;
    

    }

    Regards,

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

Sidebar

Related Questions

Taking this file as an example, I'm trying to read the data in a
I'm trying to load my UITableView with distance from current location. I'm taking small
I have a table of data that I'm trying to standardize. The data entered
I have a custom UITableView populated by JSON data brought into a NSMutableDictionary. I
I am trying to find what is the usual design/approach for static/global! data access/storage
I'm trying to iterate through a queue - taking 1 item from the queue,
I am trying to create an array of class objects taking an integer argument.
I'm trying to save myself some coding time by taking advantage of using namespace
I'm trying to figure out why one of our migration scripts is taking forever
While trying to profile my Perl program, I find that Math::Complex is taking up

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.