0
我不知道這是否可能,但是,我試圖返回一個使用CollectionView cellForItem的單元格,只有在滿足某個條件時纔可以。UICollectionViewCell只顯示何時滿足某個標準
這裏是我的功能:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FriendsRecentCell", for: indexPath) as! FriendsRecentCell
var fObj = PFObject(className: FRIENDS_CLASS_NAME)
fObj = recentArray[indexPath.row]
// Get User Pointer
let userPointer = fObj[FRIENDS_IS_FRIEND_WITH] as! PFUser
userPointer.fetchIfNeededInBackground(block: { (user, error) in
if error == nil {
// Get heys sent to you as currentUser
let query = PFQuery(className: HEYS_CLASS_NAME)
query.whereKey(HEYS_RECEIVER, equalTo: PFUser.current()!)
query.whereKey(HEYS_SENDER, equalTo: userPointer)
query.countObjectsInBackground { (count, error) in
if count != 0 {
// Get User fullname
cell.userLabelRecent.text = "\(userPointer[USER_FULLNAME]!)"
// Get Avatar
cell.avatarImageRecent.image = UIImage(named: "avatar")
cell.avatarImageRecent.layer.cornerRadius = cell.avatarImageRecent.bounds.size.width/2
let imageFile = userPointer[USER_AVATAR] as? PFFile
imageFile?.getDataInBackground(block: { (imageData, error) in
if error == nil {
if let imageData = imageData {
cell.avatarImageRecent.image = UIImage(data:imageData)
}}})
} else {
}}
}})
return cell
}
我只希望小區返回if count != 0
。有沒有什麼辦法可以做到這一點?我完全失去了。
我建議你預處理所有這些數據,把它放在一個數組中,然後加載你的collectionView。如果您有興趣,可以明天提供更多的指導。 – toddg
是的我明天會喜歡一些幫助@toddg –