【发布时间】:2017-04-06 03:38:36
【问题描述】:
我遇到了一个问题,我的应用程序崩溃并给出索引超出范围错误,但在我消除了在后台获取 imageFiles 的功能后,imageFiles[indexPath.row].getDataInBackground tableView 运行正常。我认为问题在于两个getDataInBackgroundcalls 混淆了它。
但是,我仍然需要下载 imageFiles 的数据,所以我想知道是否有人有解决方案来解决我如何在 cellForRowAtIndexPath 中做到这一点。非常感谢任何帮助:)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "userPhotoFeedCell", for: indexPath) as! FeedCell
if PFUser.current()?.objectId != nil {
cell.userUsername.text = PFUser.current()?.username
}
//downloades images and items to populate user post
postImageFiles[indexPath.row].getDataInBackground { (data, error) in
if let userPostImageData = data {
let downloadedUserPostImage = UIImage(data: userPostImageData)
cell.userFeedPhoto.image = downloadedUserPostImage
}
}
/* IF THIS ISN't COMMENTED APP GIVES INDEX OUT OF RANGE CRASH
//downloads images for user profile pic
imageFiles[indexPath.row].getDataInBackground { (data, error) in
if let imageData = data {
let downloadedImage = UIImage(data: imageData)
cell.userProfilePic.image = downloadedImage
}
}
*/
cell.postLocation.text = postLocation[indexPath.row]
cell.postCaption.text = postCaptions[indexPath.row]
cell.userFeedPhoto.image = UIImage(named: "OrangeFuego")
cell.userProfilePic.image = UIImage(named: "usericon.png")
return cell
}
【问题讨论】:
-
什么是 postImageFiles?图片 url 数组?
-
postImageFiles 是一个 PFFile。所以 var postImageFiles = [PFFile]()
标签: swift parse-platform tableview indexoutofrangeexception cell-formatting