I have a UITableView
with custom cell. Custom cell contains a UIView
. The image loaded here asynchronously. But when scrolls my table view, the images in the cell changes. Here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
MSAppointmentsModel *data = [self.appointments objectAtIndex:indexPath.row];
MSAppointmentsCell *cell = (MSAppointmentsCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *ar = [[NSBundle mainBundle] loadNibNamed:[Common checkDeviceforController:@"MSAppointmentsCell"] owner:nil options:nil];
for (id eachObject in ar) {
if ([eachObject isKindOfClass:[UITableViewCell class]]) {
cell = eachObject;
}
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSURL *imgUrl = [NSURL URLWithString:[data.cusDetails objectForKey:@"customer_image"]];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *image = [UIImage imageWithData:imgData];
dispatch_sync(dispatch_get_main_queue(), ^{
[cell.medallionView setImage:image];
});
});
if (data.comp_status == YES) {
cell.status.image = [Common imageResize:[UIImage imageNamed:@"CheckMark_green.png"] andResizeTo:cell.status.frame.size];
}
}
cell.custName.text = [data.cusDetails objectForKey:@"customer_name"];
cell.service.text = [data service];
cell.empName.text = [NSString stringWithFormat:@"by %@",[data.empDetails objectForKey:@"employee_name"]];
return cell;
}
Please help me.