變化的UIButton類,所以我有兩個UIButton's
,都連接到類LikeShape.swift
在運行時
我有另一個類名爲LikeShapeDone.swift
,我想這樣在運行時設置:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let imageCell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as! PostsCollectionViewCell
if (likedBy[indexPath.row].containsObject((PFUser.currentUser()?.username)!)){
// Post is liked by the current user
imageCell.likeButton = LikeShape()
imageCell.dislikeButton = LikeShapeDone()
}
if (dislikedBy[indexPath.row].containsObject((PFUser.currentUser()?.username)!)){
// Post is disliked by the current user
imageCell.dislikeButton = LikeShapeDone()
imageCell.likeButton = LikeShape()
}
else{
// Post is not liked by the current user
}
// <---- End ImageCell Row ---->
return imageCell
}
但沒有任何反應..我100%確定當前用戶在likedBy
和dislikedBy
LikeShape類有黑色按鈕,而LikeShapeDone有紅色按鈕,但按鈕只是一直黑色......任何建議?
建議:創建一個按鈕,並改變在運行時鍵入不是整個類或整個按鈕。 –
@AshishKakkad你的意思是:'imageCell.likeButton = LikeShape()'?這是我的嘗試,並沒有工作。 –
創建一個按鈕LikeDislikeButton.type =喜歡或不喜歡。在運行時更改 –