Hi I am working on UITableView. I have added a table in my view programmatically and populated it with some data by adding UILable as a subview of each cell. Table has 21 rows. Problem is that when i scroll up or down, the data in the first two rows and last 2 or 3 rows is overlapped with some other row's data. For example first two bowlers data is over lapped with first two batsmen data. Task is to first show a list of batsman then leave 2 cells empty and then show a list of bowlers in the same table. My code is
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *string1;
NSString *string2;
if(indexPath.row < [inningObject.battingLine count]){
Batter *cBatter = [inningObject.battingLine objectAtIndex:indexPath.row];
string1 = cBatter.batterName;
string2 = cBatter.runs;
}else if(indexPath.row > [inningObject.battingLine count]+1){
Bowler *cBowler = [inningObject.bowlingLine objectAtIndex: indexPath.row-[inningObject.battingLine count]-2]; // start from zero for next NSArray
string1 = cBowler.bowlerName;
string2 = cBowler.wickets;
}
CGRect a=CGRectMake(5, 0, 320, 38);
if(indexPath.row < [inningObject.battingLine count] || indexPath.row >= [inningObject.battingLine count]+2){
CGRect string1Rect = CGRectMake(5, 10, 150, 18);
UILabel *string1Label = [[UILabel alloc] initWithFrame:string1Rect];
string1Label.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
string1Label.textAlignment = UITextAlignmentLeft;
string1Label.text = string1;
string1Label.font = [UIFont boldSystemFontOfSize:17];
[cell.contentView addSubview: string1Label];
[string1Label release];
CGRect string2Rect = CGRectMake(240, 10, 70, 18);
UILabel *string2Label = [[UILabel alloc] initWithFrame:string2Rect];
string2Label.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
string2Label.textAlignment = UITextAlignmentLeft;
string2Label.text = string2;
string2Label.font = [UIFont boldSystemFontOfSize:17];
[cell.contentView addSubview: string2Label];
[string2Label release];
}
return cell;
}