I have a table view. I have created a method that takes all the data it needs with a cell and returns the updated cell. In that method I have:
my cell for row goes like this static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
cell = myCellcreationMethod : cell : reuseIdentifier: other arguments;
MycellCreation method goes like this: MycellCreation with args some strings , the cell and the reuseIdentifier.
if ( cell == nil ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
//Here code that creates a custom image view something like:
thumbnailView = [[UIImageView alloc] initWithFrame:CGRectMake(9, 9, 70, 70)];
thumbnailView = [imUtil getImageViewWithRoundedCorners:thumbnailView andRadius:10.0];
thumbnailView.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:thumbnailView];
//same here for another image view,
//same again
//and there same for a UILabel
}
//Here I set in each case the data for each imageView from above and the UIlabel text like
UIImage *thumbnailImage = [imUtil getThumbnailImageWithFile:thumbnail];
thumbnailView.image = thumbnailImage;
//the others go here
textLabel.text = @"something";
return cell;
All cells have the same identifier since they all are of the same type. But when I scroll down, instead of showing the data that corresponds to the next object in my list (new thumbnail new image, new text in uilabel) it replicates the first ones. I guess it loads the reused cell but does not put the new data in.
Any suggestions please?
I found the answer. I shouldn't just add the views with a method in my tableview class. I created a NEW subclass of UITableView, initialized it with my custom views and created a method in there that sets the new data. then used them two and it works like a charm!