使用三方SDWebImage, 使用sd_setImageWithUrl,设置占位图片,当TableViewCell上的图片没有刷新出来的时候,保证其位置不会被占用。
eg. [cell.titltImageView sd_setImageWithURL:[NSURL URLWithString:car.newsImage] placeholderImage:[UIImage imageNamed:@”zhanwei2_1”]];
//用kvo监听
方法:重点内容
static void *imageViewFrameKey = &imageViewFrameKey;
- (void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary )change context:(void *)context;
- eg:
(void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary )change context:(void *)context
{
if (context == imageViewFrameKey) {//此时监听到imageView的frame发生变化,改成自定义的frame值 UIImageView *imageView = (UIImageView *)object; CGRect newRect = CGRectMake(6, 4, 82, 51); if (!CGRectEqualToRect(imageView.frame, newRect)) { imageView.frame = newRect; }
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}重点内容