Je travaille sur UITableView. J'ai ajouté une table dans ma vue par programme et l'ai peuplée avec quelques données en ajoutant UILable comme sous-vue de chaque cellule. La table a 21 rangées. Le problème est que lorsque je fais défiler vers le haut ou vers le bas, les données dans les deux premières lignes et les dernières 2 ou 3 lignes se chevauchent avec les données d'autres lignes. Par exemple, les données des deux premiers quilleurs sont surclassées avec les deux premières données batteurs. La tâche est de montrer d'abord une liste de batteur puis de laisser 2 cellules vides, puis de montrer une liste de quilleurs dans la même table. Mon code estUITableView chevauchement de texte
- (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;
}
Merci beaucoup pour le domino de réponse. Je vais avec la deuxième option que vous avez recommandée. :-) – Aqueel