Swift网络请求,数据模型,图片缓存,自动布局,上拉刷新下拉加载
来源:互联网 发布:武汉淘宝产品拍摄 编辑:程序博客网 时间:2024/05/20 06:56
Alamofire.request(.POST, url, parameters:parameters).responseJSON{response in
self.firstTableView.doneRefresh()
self.isLoading=false
switch response.result {
case .Success:
if let dict = response.result.value {
let errorCount:String=dict["error"] as! String
self.pages = dict["totalPages"] as! Int
if errorCount=="0"{
if self.page==1{
self.dataArray.removeAllObjects()
}
let array = ProductModel.jsonToModelList(dict["rows"]) as! Array<ProductModel>
self.dataArray.addObjectsFromArray(array)
self.firstTableView.reloadData()
}
}
case .Failure(let error):
print(error)
}
}
let URL = NSURL(string: "http://www.bysuper.com/"+newValue.ProductImage!)!
productImageView.kf_setImageWithURL(URL, placeholderImage: nil,
optionsInfo: [.Transition(ImageTransition.Fade(1))],
progressBlock: { receivedSize, totalSize in
// print("\(indexPath.row + 1): \(receivedSize)/\(totalSize)")可以用来显示图片加载的进度
},
completionHandler: { image, error, cacheType, imageURL in
// print("\(indexPath.row + 1): Finished")
})
KingfisherManager.sharedManager.cache.clearMemoryCache()
KingfisherManager.sharedManager.cache.clearDiskCache()
4. SnapKit(https://github.com/SnapKit/SnapKit)自动布局框架和Masonry是出自同一个作者的手
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
//商品图片
productImageView=UIImageView()
self.contentView.addSubview(productImageView)
//商品名称
titleLabel=UILabel()
titleLabel.numberOfLines=0
self.contentView.addSubview(titleLabel)
//商品价格
priceLabel=UILabel()
priceLabel.textColor=UIColor.redColor()
self.contentView.addSubview(priceLabel)
//商品销量
countLabel=UILabel()
countLabel.textColor=UIColor.lightGrayColor()
countLabel.textAlignment=NSTextAlignment.Right
self.contentView.addSubview(countLabel)
productImageView.snp_makeConstraints("", line: 0) { (make) -> Void in
make.width.lessThanOrEqualTo(80)
make.height.lessThanOrEqualTo(80)
make.left.equalTo(self.contentView).offset(padding)
make.top.equalTo(self.contentView).offset(padding)
}
titleLabel.snp_makeConstraints("", line: 0) { (make) -> Void in
make.width.lessThanOrEqualTo(screenWidth-3*padding-80)
make.height.lessThanOrEqualTo(50)
make.left.equalTo(productImageView.snp_right).offset(padding)
make.top.equalTo(self.contentView).offset(padding)
}
priceLabel.snp_makeConstraints("", line: 0) { (make) -> Void in
make.width.lessThanOrEqualTo((screenWidth-4*padding)/2.0)
make.height.lessThanOrEqualTo(50)
make.left.equalTo(productImageView.snp_right)
make.bottom.equalTo(self.contentView.snp_bottom).offset(-padding)
}
countLabel.snp_makeConstraints("", line: 0) { (make) -> Void in
make.width.lessThanOrEqualTo((screenWidth-4*padding)/2.0)
make.height.lessThanOrEqualTo(30)
make.right.equalTo(self.contentView.snp_right).offset(-padding)
make.bottom.equalTo(self.contentView.snp_bottom).offset(-padding)
}
}
weak var weakSelf = self as FirstViewController
// 及时上拉刷新
firstTableView.nowRefresh({ () -> Void in
if weakSelf!.isLoading{
self.firstTableView.doneRefresh()
return
};
weakSelf?.page = 1
weakSelf?.isLoading=true
weakSelf?.initData()
})
// 上啦加载更多
firstTableView.toLoadMoreAction({ () -> Void in
if weakSelf!.isLoading{
self.firstTableView.doneRefresh()
return
};
if (weakSelf?.page < weakSelf?.pages){
weakSelf?.isLoading=true
weakSelf?.page += 1
weakSelf?.initData()
}else{
weakSelf?.firstTableView.endLoadMoreData()
weakSelf?.isLoading=false
}
})
- Swift网络请求,数据模型,图片缓存,自动布局,上拉刷新下拉加载
- fresco加载图片+retrofit网络请求+rxjava2+xrecyclerview下拉刷新上拉加载
- PullToRefreshListView 上拉加载,下拉刷新 + AsyncTask 网络请求 + gson 自动解析
- XListView上拉刷新下拉加载(网络请求json)
- HttpUtils请求网络+xlistview上拉刷新,下拉加载
- 仿知乎下拉刷新上拉自动加载
- RecycleView 布局布局管理器 上拉加载 下拉刷新
- iOS开发用AFNetworking和MJRefresh实现网络请求和下拉刷新、上拉加载
- xListView(上拉刷新下拉加载,xml解析)中添加网络请求
- MVP模式的OKhttp请求网络数据,xrecyclerview上拉刷新,下拉加载
- MVP请求网络数据上拉刷新下拉加载加断点续传
- Swift-MJRefresh下拉刷新及上拉加载实践
- Swift快速集成下拉刷新和上拉加载更多
- swift开发---- XWSwiftRefresh 下拉刷新 上拉加载
- 实现上拉刷新下拉加载的布局
- 自定义布局实现listview上拉加载下拉刷新
- 自定义listview布局实现上拉加载,下拉刷新
- recyclerview,okHttp,布局切换,springView上拉刷新下拉加载
- 仿微信开发(二)--系统语言设置
- MVC流程图
- Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~
- 【转载】SQL中declare申明变量 declare @id int
- android蓝牙4.0开发
- Swift网络请求,数据模型,图片缓存,自动布局,上拉刷新下拉加载
- Spring4+Hibernate4+Mybatis Maven的pom配置
- OpenGL学习脚印: 向量和矩阵要点(math-vector and matrices)
- BAT命令--FOR使用方法及举例
- Qml和C++开发的学生信息管理软件一
- iOS真机运行出现The certificate used to sign "APP名" has either expired or has been revoked.
- Android - R.java文件不自动更新时解决方案
- 【转载】sql 循环语句几种方式
- Java中HashMap遍历的两种方式