내 앱이 충돌하여 인덱스 범위를 벗어난 오류가 발생했지만 백그라운드에서 imageFiles를 가져 오는 기능을 제거한 후에는 imageFiles[indexPath.row].getDataInBackground
tableView가 실행됩니다. 정상적으로. 문제는 두 개의 getDataInBackground
호출이 그것을 혼란스럽게 만들었다 고 생각합니다.getDataInBackground에 대한 두 번의 호출로 cellForRowAtIndexPath에서 스위프트 인덱스를 벗어났습니다.
그러나 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]() –