В ячейке табличного представления есть изображение и метка.Когда пользователь создает место для публикации, мне нужно скрыть вид изображения и уменьшить высоту ячейки.Если пользователь создает сообщение с изображением, то мне нужно скрыть ярлык и показать представление изображения и увеличить высоту ячейки.
Вот код, который я пробовал:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell", for: indexPath) as! HomeTableViewCell
guard posts.count > 0 else {
return cell
}
cell.post = posts[indexPath.row]
cell.homeVC = self
cell.delegate = self
cell.profileImageView.tag = indexPath.row
cell.postImageView.tag = indexPath.row
cell.shareImageView.tag = indexPath.row
cell.nameLabel.tag = indexPath.row
cell.productRatingLabel.tag = indexPath.row
// cell.postTime.tag =
// cell.postTime.tag =
cell.postTime.tag = indexPath.row
cell.locationName.tag = indexPath.row
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell", for: indexPath) as! HomeTableViewCell
if cell.postImageView == nil {
cell.postImageView.isHidden = true
cell.locationName.isHidden = false
return 100
} else {
cell.postImageView.isHidden = false
cell.locationName.isHidden = true
return 498
}
}
![excepted result](https://i.stack.imgur.com/2tK78.jpg)
это то, что я хочу ..