tableView의 행 개수 값을 표시하는 tableViewHeader에 UILabel이 있습니다. 행을 삭제 한 후 행을 삭제하자마자 사용자가 다른 VC로 이동 한 후 다시 countView 값이 새로 고쳐지는 tableView로 돌아온 후에 tableViewHeader UILabel에서 카운트 값을 업데이트하고 싶습니다. 다시, 셀이 tableView에서 삭제 되 자마자 동일한 뷰에서 UILabel 값을 업데이트하고 싶습니다. 어떤 도움을 주셔서 감사합니다!업데이트 셀이 삭제 된 후 tableViewHeader에있는 UILabel
// tableViewHeader 클래스는
class Header: UITableViewHeaderFooterView {
var placeList = [Place]()
var placesDictionary = [String: Place]()
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let nameLabel: UILabel = {
let label = UILabel()
// display the number of tableView rows in UILabel
label.text = "## of Places"
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont.boldSystemFont(ofSize: 14)
return label
}()
func setupViews() {
addSubview(nameLabel)
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
}
}
// headerView 방법
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: "headerId") as? Header else { return nil }
view.nameLabel.text = "user has visited \(placeList.count) Places"
return view
}
// tableViewCell 기능
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
if let place = placeList[indexPath.row].place {
let uid = FIRAuth.auth()?.currentUser?.uid
let ref = FIRDatabase.database().reference().child("users").child(uid!).child("Places")
ref.queryOrdered(byChild: "place").queryEqual(toValue: place).observe(.childAdded, with: { (snapshot) in
snapshot.ref.removeValue(completionBlock: { (error, reference) in
if error != nil {
print("There has been an error:\(String(describing: error))")
}
})
})
}
placeList.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .left)
}
}
테이블 "tableView.reloadData()를 다시로드 해 보셨습니까? –
didEndEditingRowAt 대리자 함수를 사용해 보셨습니까? –