【发布时间】:2018-01-18 05:47:57
【问题描述】:
我已经从 url 实现了一组图像并将其显示在集合视图和表格视图上,并在加载应用程序后部署在 iphone 5 设备中,图像页面没有快速滚动并且需要更多时间延迟如何避免这种情况任何人都可以帮忙我 ?
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imageArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "productsCell", for: indexPath) as! productsCell
let arr = imageArray[indexPath.row]
let urls = NSURL(string: arr)
let data = NSData (contentsOf: urls! as URL) //make sure your image in this url does exist, otherwise unwrap in a if let check
cell.productImage.image = UIImage(data: data! as Data)
cell.productName.lineBreakMode = NSLineBreakMode.byWordWrapping
cell.productName.numberOfLines = 2
cell.productName.text = self.productName[indexPath.row]
cell.productPrice.text = self.productprice[indexPath.row]
cell.buynowButton .addTarget(self, action: #selector(buyNowButton(_:)), for:UIControlEvents.touchUpInside)
cell.cartButton .addTarget(self, action: #selector(cartButton(_:)), for:UIControlEvents.touchUpInside)
return cell
}
【问题讨论】:
-
首先您必须下载缓存中的所有图像,然后在滚动时从缓存中获取图像。将来可能是内存问题。
-
如何下载缓存中的图像我不知道我是 swift 3 的新手?@NilayShah
-
请参考链接。它在目标 C 中。stackoverflow.com/a/14961854/1746086
-
如果可能,请发布 swift 3 @NilayShah 的代码
标签: ios uitableview swift3 uiimageview