我的問題是當我向下滾動我的UITableView時,它看起來太滯後了。圖片從Facebook抓取。Swift - UITableView滯後於圖像
我的代碼
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("UserCell", forIndexPath: indexPath) as UITableViewCell
let user = users[indexPath.row] as User //2
if let nameLabel = cell.viewWithTag(100) as? UILabel { //3
nameLabel.text = user.name
}
if let dateCreatedLabel = cell.viewWithTag(101) as? UILabel {
dateCreatedLabel.text = user.distance
}
if let profilePictureView = cell.viewWithTag(103) as? UIImageView {
if let url = NSURL(string: "https://graph.facebook.com/\(user.profilePhoto)/picture?type=large") {
if let data = NSData(contentsOfURL: url){
profilePictureView.contentMode = UIViewContentMode.ScaleAspectFit
profilePictureView.image = UIImage(data: data)
}
}
}
return cell
}
請指點如何使其光滑。
查找有關在後臺加載圖像的問題和解答。 – 2015-02-07 09:44:03
http://stackoverflow.com/questions/24231680/swift-loading-image-from-url – 2015-02-07 09:56:15