У меня есть UITableViewCell с UITextView и UIView
Я пытаюсь скрыть / показать UIView
Ограничения - TextView:
Трейлинг к Superview равен 2
Привод к Superview равен 2
Верх к Superview равен 2
Нижний к Superview равен40
UIVIew:
Трейлинг к Superview
Привод к Superview
Снизу к Superview
Высота 35
В классе Cell я подключаю TextView BottomConstraint
Класс UITableViewCell:
@IBOutlet weak var myTextView: UITextView!
@IBOutlet weak var detailView: UIView!
@IBOutlet weak var detailLabel: UILabel!
@IBOutlet weak var TextViewConstraintToBottom: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
detailView.isHidden = true
if detailView.isHidden == true {
TextViewConstraintToBottom.constant = 0
} else {
TextViewConstraintToBottom.constant = 40
}
}
В ViewController с UITableView:
var handle: DatabaseHandle?
var ref: DatabaseReference?
var quoteList: [String] = []
var songArray: [String] = []
override func viewWillAppear(_ animated: Bool) {
myTableView.estimatedRowHeight = 100
myTableView.rowHeight = UITableViewAutomaticDimension
}
override func viewDidLoad() {
super.viewDidLoad()
myTableView.dataSource = self
myTableView.delegate = self
dataCatch()
}
func dataCatch() {
ref = Database.database().reference()
handle = ref?.child("Цитаты").child("\(cat)").child("\(quoteNAme)").observe(.childAdded, with: { (snapshot) in
let username = snapshot.value as? NSDictionary
if let us = username?["name"] {
self.quoteList.append(us as! String)
self.quoteList = self.quoteList.filter(){$0 != "1"}
self.myTableView.reloadData()
}
if let us = username?["song"].unsafelyUnwrapped {
self.celT?.detailView.isHidden = false
self.songArray.append(us as! String)
self.myTableView.reloadData()
}
})
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! QuoteTableVC
let indexP = indexPath.row
cell.myTextView.text = quoteList[indexP]
cell.detailLabel.text = songArray[indexP]
return cell
}
В базе данных у меня есть структура
Я решил
В ViewController:
func dataCatch() {
ref = Database.database().reference()
handle = ref?.child("Цитаты").child("\(cat)").child("\(quoteNAme)").observe(.childAdded, with: { (snapshot) in
let username = snapshot.value as? NSDictionary
if let us = username?["name"] {
self.quoteList.append(us as! String)
self.quoteList = self.quoteList.filter(){$0 != "1"}
self.myTableView.reloadData()
}
if snapshot.hasChild("song") {
let us = username?["song"]
self.songArray.append(us as! String)
} else {
let tet = "1"
// self.celT?.detailView.isHidden = true
self.songArray.append(tet as! String)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.detailLabel.text = songArray[indexP]
if cell.detailLabel.text != "1" {
cell.detailView.isHidden = false
cell.butConstraint.constant = 40
} else {
cell.detailView.isHidden = true
cell.butConstraint.constant = 0
}