UITableViewCell加载图片
来源:互联网 发布:西门子plc300编程软件 编辑:程序博客网 时间:2024/05/27 08:13
数据模型
.h文件
//图片属性
@property(nonatomic,strong) UIImage *newsImage;
//图片下载状态
@property(nonatomic,assign) BOOL isDownLoading;
//下载图片的方法
-(void)loadImage;
@property(nonatomic,assign) NSInteger rowNum;
@property(nonatomic,strong) NSString *Id;
@property(nonatomic,strong) NSString *title;
@property(nonatomic,strong) NSString *type;
@property(nonatomic,strong) NSString *cid;
@property(nonatomic,strong) NSString *cname;
@property(nonatomic,strong) NSString *newsUrl;
@property(nonatomic,strong) NSString *typeId;
@property(nonatomic,assign) NSInteger sequence;
@property(nonatomic,assign) NSInteger attribute;
@property(nonatomic,strong) NSString *lastUpdateTime;
@property(nonatomic,strong) NSString *PUBLISHDATE;
@property(nonatomic,strong) NSString *picUrl;
@property(nonatomic,strong) NSString *summary;
@property(nonatomic,assign) NSInteger commentCount;
@property(nonatomic,strong) NSString *newsId;
.m文件
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
//占用系统关键字的key值需要重新指定映射
if ([key isEqualToString:@"id"]) {
_Id = value;
NSLog(@"%@",key);
}
}
//此方法适用于我们调试使用(debug模式下),检验model数据,直观的观察到model的值(默认打印的是地址)
- (NSString *)description
{
return [NSString stringWithFormat:@"rowNum=%ld,Id=%@,title=%@,type=%@,cid=%@,cname=%@,newsUrl=%@,typeId=%@,sequence=%ld,attribute=%ld,lastUpdateTime=%@,PUBLISHDATE=%@,picUrl=%@,summary=%@,commentCount=%ld",_rowNum,_Id,_title,_type,_cid,_cname,_newsUrl,_typeId,_sequence,_attribute,_lastUpdateTime,_PUBLISHDATE,_picUrl,_summary ,_commentCount];
}
//下载图片的方法
-(void)loadImage
{
[ZQImageDownLoader iamgeDownLoad:_picUrl block:^(UIImage *image) {
_newsImage = image;
//表示加载完成
_isDownLoading = NO;
}];
//先走这个方法,表示正在加载
_isDownLoading = YES;
}
方法一:SDWebImage第三方
#warning 方法一:使用第三方
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:news.picUrl] placeholderImage:[UIImage imageNamed:@"image0.jpg"]];
方法二:KVO
//第一次运行时,图片为空并且还未加载
// if(news.newsImage == nil && news.isDownLoading == NO)
// {
// //则显示一张默认图片
// cell.imageView.image = [UIImage imageNamed:@"image0.jpg"];
//
// //加载图片
// [news loadImage];
//
// //增加观察者
// [news addObserver:self forKeyPath:@"newsImage" options:NSKeyValueObservingOptionNew context:(__bridge void*)indexPath];
// }
// else{
// //当图片正在加载
// if(news.newsImage == nil)
// {
// cell.imageView.image = [UIImage imageNamed:@"image0.jpg"];
//
// }
// else{
//
// cell.imageView.image = news.newsImage;
// }
// }
//
// return cell;
//}
//
//
//
//-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
//{
// //字典通过键值找到的值是id类型,在做项目期间,要注意写强转
// UIImage *image = (UIImage *)(change[@"new"]);
//
// if (image == nil) {
// return;
// }
//
// //取出可视区域cell所在的位置的集合
// NSArray *array = [self.tableView indexPathsForVisibleRows];
// //获取被观察的model对象
// NSIndexPath *indexPath = (__bridge NSIndexPath *)(context);
// //判断被观察的对象是否显示在可视区域
// if ([array containsObject:indexPath]) {
// //如果在显示区域,我们取出对应的cell更新数据
// MyCell *cell = (MyCell *)[self.tableView cellForRowAtIndexPath:indexPath];
// cell.imageView.image = image;
// //更新cell
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
// }
//
// //移除观察者
// [object removeObserver:self forKeyPath:@"newsImage"];
//
//
//}
- UITableViewCell 图片加载
- UITableViewCell加载图片
- iphone(UITableViewCell)动态加载图片
- iphone(UITableViewCell)动态加载图片
- iphone(UITableViewCell)动态加载图片
- UITableViewCell加载网络图片自适应cell高度初探索
- iOS UITableViewCell 多线程 网络+沙盒的图片加载以及第三方框架SDWebImage方式加载
- UITableView 重用 UITableViewCell 并异步加载图片时会出现图片错乱的情况
- UITableView 重用 UITableViewCell 并异步加载图片时会出现图片错乱的情况的原因
- 加载本地UITableViewCell
- UITableViewCell派生类加载Xib
- UITableViewCell Storyboard加载错误解决
- Xib设计UITableViewCell然后动态加载
- 从nib文件加载自定义的UITableviewCell
- Xib设计UITableViewCell然后动态加载
- 通过xib加载UITableViewCell的新方式
- 从nib文件加载自定义的UITableviewCell
- 通过xib加载UITableViewCell的新方式
- [C++面试] linux C++服务器面试题
- 组播技术
- php函数:fsockopen
- 如何从PDF文件中提取矢量图
- TCP/IP协议三次握手与四次握手流程解析
- UITableViewCell加载图片
- 你是什么(外篇)
- Linux中断上下文和进程上下文(一)
- [腾讯面试] 2016届腾讯实习生招聘笔试+面试(技术岗)
- VB.net视频打开方法
- HDU1028(母函数)
- Matlab-vision包学习-Feature Detection,Extraction and Matching-FAST角点检测
- 【AMPPZ2014】【BZOJ4147】Euclidean Nim
- [腾讯面试] 2016届实习生招聘研发面试经验(已获阿里内推+腾讯offer)