Ios 单元格中快速隐藏/显示UIView(数据库中的数据)
我的UITableViewCell带有UITextView和Ios 单元格中快速隐藏/显示UIView(数据库中的数据),ios,swift,uitableview,firebase,firebase-realtime-database,Ios,Swift,Uitableview,Firebase,Firebase Realtime Database,我的UITableViewCell带有UITextView和UIView 我正在尝试隐藏/显示UIView 约束-文本视图: 尾随到Superview等于2 导致Superview等于2 顶部到超级视图等于2 从底部到超级视图等于40 UIVIew: 跟踪到Superview 通向Superview 从底部到超级视图 身高35 在Cell类中,我是connecttextview UITableViewCell类: @IBOutlet weak var myTextView: UITextVi
UIView
我正在尝试隐藏/显示UIView
约束-文本视图:
尾随到Superview等于2
导致Superview等于2
顶部到超级视图等于2
从底部到超级视图等于40
UIVIew:
跟踪到Superview
通向Superview
从底部到超级视图
身高35
在Cell类中,我是connecttextview
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
}
}
在具有UITableView的ViewController中:
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
}
在
cellForRow
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UI TableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! QuoteTableVC
// hide = check your model whether it has song or not
if hide {
cell.TextViewConstraintToBottom.constant = 0
}
else {
cell.TextViewConstraintToBottom.constant = 40
}
}