Поэтому у меня есть два UIButton's
, оба подключены к классу LikeShape.swift
Изменить UIButton класс во время выполнения
У меня есть еще один класс с именем 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 = нравится или не нравится. изменение во время выполнения –