变化的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 =喜欢或不喜欢。在运行时更改 –