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 –