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?