Я работаю над UITableView. Я добавил таблицу в мое представление программно и заполнил ее некоторыми данными, добавив UILable в качестве подпредставления каждой ячейки. Таблица состоит из 21 строки. Проблема заключается в том, что когда я прокручиваю вверх или вниз, данные в первых двух строках и последних 2 или 3 строках перекрываются данными других строк. Например, данные первых двух боулеров перекрываются данными первых двух игроков с битой. Задача состоит в том, чтобы сначала показать список игроков с битой, затем оставить 2 ячейки пустыми, а затем показать список игроков в той же таблице. Мой код
- (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;
}