dans ma table voir la taille de la cellule correspond à la taille de l'écran entier. donc il ne crée que deux cellules mais à partir de la 3ème cellule il utilise le contenu de l'ancienne cellule ... donc je reçois les données incorrectes ..uitableview chargement des cellules avec le contenu des cellules précédentes
comment résoudre ce problème ...?
merci.
- (UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:CellIdentifier] autorelease];
for(UIView *v in [cell.contentView subviews])
[v removeFromSuperview];
curCellNo = indexPath.row;
if(curCellNo == 0){
min = 0;
max = 8;
x=0;
y=yForFirst;
col = 1;
}else{
if(curCellNo < prevCellNo){
min = min-12;
max = max-12;
}else{
min = max;
max = min+12;
}
x=0;
y=0;
}
prevCellNo = curCellNo;
NSLog(@"Max...%d",max);
NSLog(@"Min...%d",min);
NSLog(@"songsCount...%d",[songs count]);
for(int i=min; i<max && i<[songs count]; i++){
Song *thesong = [self.songs objectAtIndex:i];
CGRect frame;
frame.size.width=coverWidth; frame.size.height=coverHeight;
frame.origin.x=x; frame.origin.y=y;
LazyImageView* asyncImage = [[[LazyImageView alloc] initWithFrame:frame]autorelease];
NSURL* url = [NSURL URLWithString:thesong.cover];
[asyncImage loadImageFromURL:url];
UILabel *label = [[[UILabel alloc]initWithFrame:CGRectMake(x, y+artistLabelYPos, artistLabelWidth, artistLabelHeight)]autorelease];
label.text = [thesong.title stringByAppendingString:[@"\nby " stringByAppendingString:thesong.artist]];
[label setTextAlignment:UITextAlignmentLeft];
label.numberOfLines = 0;
label.font = [UIFont systemFontOfSize:artistLabelFontSize];
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor darkTextColor];
label.alpha = 0.75;
UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
playBtn.frame = CGRectMake(x+playBtnXPos, y+playBtnYPos, playBtnWidth, playBtnHeight);
[playBtn addTarget:self action:@selector(playBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
if(playingButton && streamer){
if(playingButtonTag == i && [streamer isPlaying]){
[playBtn setBackgroundImage:[UIImage imageNamed:pauseBtnimgName] forState:UIControlStateNormal];
playingButton = playBtn;
}else [playBtn setBackgroundImage:[UIImage imageNamed:playBtnimgName] forState:UIControlStateNormal];
}else [playBtn setBackgroundImage:[UIImage imageNamed:playBtnimgName] forState:UIControlStateNormal];
playBtn.tag = i;
[cell.contentView addSubview:asyncImage];
[cell.contentView addSubview:label];
[cell.contentView addSubview:playBtn];
label = nil;
asyncImage = nil;
if(curCellNo == 0){
y += estCoverHeight;
if(y>=(estCoverHeight*noOfRowsInCell)){
col++;
x += estCoverWidth;
if(col>=3)
y=0;
else
y=yForFirst;
}
}else{
col =3;
y += estCoverHeight;
if(y>=(estCoverHeight*noOfRowsInCell)){
x += estCoverWidth;
y=0;
}
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.contentView.transform = CGAffineTransformMakeRotation(M_PI/2);
return cell;
}
pouvez-vous poster votre implémentation de la méthode 'tableView: cellForRowAtIndexPath:'? – filipe