OStack程序员社区-中国程序员成长平台

标题: ios - 为什么表格 View 滚动滞后? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 16:42
标题: ios - 为什么表格 View 滚动滞后?

我实现了一个表格 View ,但滚动滞后。为什么会滞后?我正在重复使用电池,但它仍然滞后。当我滚动时,内存会激增并在滚动停止时恢复正常。如果有任何用处,我在表格 View 单元内实现了一个 Collection View 。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell: BoxCell = table.dequeueReusableCellWithIdentifier("CELL", forIndexPath: indexPath) as! BoxCell

    cell.pic.image = pic[indexPath.row].circle


    return cell
}

extension UIImage {
var circle: UIImage? {
    let square = CGSize(width: min(size.width, size.height), height: min(size.width, size.height))
    let imageView = UIImageView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: square))
    imageView.contentMode = .ScaleAspectFill
    imageView.image = self
    imageView.layer.cornerRadius = square.width/2
    imageView.layer.masksToBounds = true
    UIGraphicsBeginImageContext(imageView.bounds.size)
    guard let context = UIGraphicsGetCurrentContext() else { return nil }
    imageView.layer.renderInContext(context)
    let result = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return result
}

}



Best Answer-推荐答案


您的图片有多大?如果它们是大图像表会变慢。我最近遇到了这个问题。使用较小的图像使其再次更快。

关于ios - 为什么表格 View 滚动滞后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37720662/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4