i have a tableView with a custom cell, my first cell is different with the others cells. ( it contain a small image and a label). I am doing like this :
#
pragma mark - tableView data source methods
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
SuggestionCarteCell *cell = (SuggestionCarteCell *)[tableView dequeueReusableCellWithIdentifier:@"carteCell"];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SuggestionCarteCell" owner:nil options:nil] ;
cell = [nib objectAtIndex:0];
}
if (indexPath.row == 0) {
// crer l'image
NSLog(@" je suis dans row 0");
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(21, 9, 13, 26)];
imageView.image = [UIImage imageNamed:@"iconeLocation"];
[cell addSubview:imageView];
cell.labelRegion.frame = CGRectMake(21+13+10, cell.labelRegion.frame.origin.y,cell.labelRegion.frame.size.width , cell.labelRegion.frame.size.height);
cell.labelRegion.text = [NSString stringWithFormat:@"A proximité,"];
}
else{
Region *region = [Region new];
region =(Region *) [arrayRegion objectAtIndex:indexPath.row];
cell.labelRegion.text =region.nomRegion;
}
return cell;
}
in the first time it’s good, but when i scroll my first cell ( the small image added) appear in the other rows. What i am doing wrong ? thanks
You have two types of cell but only one reuse identifier.
Two options: