【iOS开发-68】APP下载案例:利用tableView自带的cell布局+缓存池cell复用时注意button状态的检查
(1)效果

(2)源码与资源下载
http://pan.baidu.com/s/1pJLo2PP
(3)总结
——核心是利用UITableView里面自带的cell来制作样式同样的cell。
与之对应的是,由于不是整个xib文件,所以载入这个cell时有一些差别,仅仅须要在缓存池中取就可以(利用ID)。
+(instancetype)cellWithTableView:(UITableView *)tableView{
static NSString *ID=@"app";
WPAppCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
return cell;
}——第二个知识点。就是推断状态,在赋值的时候也要覆盖新的状态(这里主要是下载button的状态),下面第一个方法是赋值时检查状态,第二个方法是点击button后button状态值改变。
-(void)setApp:(WPApps *)app{
_app=app;
self.icon.image=[UIImage imageNamed:app.icon];
self.name.text=app.name;
self.desc.text=[NSString stringWithFormat:@"%@ | %@",app.size,app.download];
if (!app.isDownloaded) {
self.download.enabled=YES;
}else{
self.download.enabled=NO;
}
}
- (IBAction)clickDownload {
self.download.enabled=NO;
self.app.downloaded=!self.app.isDownloaded;
}——另一个万年不变的知识点:代码封装。
浙公网安备 33010602011771号