我正在制作一个应用程序,其中我将图像视图放在uitableview单元格中,但是当我在故事板上打开我的图像视图位置然后运行应用程序但是该图像没有根据下面的uiimage视图的位置出现我正在添加屏幕截图
及以下是我在indexpath代码
行的tableview单元格 static NSString *tableviewidentifier = @"cell";
__block tablecellTableViewCell *cell= [self.activitiesTableView_ dequeueReusableCellWithIdentifier:tableviewidentifier];
if(cell==nil)
{
cell = [[tablecellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableviewidentifier];
}if(indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1){
}
__block NSString *row = [NSString stringWithFormat:@"%d",indexPath.row];
UILabel *valuedate = (UILabel *)[cell viewWithTag:21];
UILabel *msg = (UILabel *)[cell viewWithTag:22];
UILabel *date = (UILabel *)[cell viewWithTag:23];
UILabel *time = (UILabel *)[cell viewWithTag:24];
if([[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageRead"] intValue]==0)
{
cell.contentView.backgroundColor=[UIColor colorWithRed:(245/255.0) green:(245/255.0) blue:(245/255.0) alpha:1];
}
else
{
cell.contentView.backgroundColor=[UIColor clearColor];
}
valuedate.text=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"offerTitle"];
msg.text=@"How are you?";
if(![[imagesDictionary allKeys] containsObject:row]) //if image not found download and add it to dictionary
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSString *img=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"offerPhoto"];// here i am getting image path
NSURL *url = [NSURL URLWithString:img];
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
dispatch_sync(dispatch_get_main_queue(), ^{ //in main thread update the image
[imagesDictionary setObject:image forKey:row];
cell.imageView.image = image;
cell.textLabel.text = @""; //add this update will reflect the changes
NSLog(@"loading and addig to dictionary");
});
});
}
else
{
cell.imageView.image = [imagesDictionary objectForKey:row];
NSLog(@"retriving from dictioary");
}
date.text=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageDate"];
time.text=[[self.inboxmessagesarray objectAtIndex:indexPath.row]objectForKey:@"messageTime"];
return cell;
}
答案 0 :(得分:2)
我认为您正在设置单元格的默认图像而不是自定义单元格中存在的图像视图
上面代码中的 cell.imageView.image
是单元格的默认图像。将自定义单元格中显示的图像视图的名称更改为某个不同的名称,例如profileImageView
,然后将图像设置为类似
cell. profileImageView.image = myImage;
在上面的代码中你正在使用自定义tableview单元格的图像视图