Reputation: 83
I'm trying to build an app similar to iOS native Reminders app. Where there's a list of items with header and footer. Each cell contains an UITextView
that will dynamic change cell height when user typing. Footer view contains the same cell view, except I want it to be a footer so it would stick to the bottom view. I have cell set to dynamic height.
checklistTable.rowHeight = UITableViewAutomaticDimension
checklistTable.estimatedRowHeight = 60
checklistTable.sectionFooterHeight = UITableViewAutomaticDimension
checklistTable.estimatedSectionFooterHeight = 60
here is the logic for update cell height while typing, this works perfectly for regular cells, but does not work for footer view. I set an breakpoint in viewForFooterInSection, it was never called after initial loading.
func textViewDidChange(_ textView: UITextView) {
let startHeight = textView.frame.size.height
let calcHeight = textView.sizeThatFits(textView.frame.size).height
if startHeight != calcHeight {
UIView.setAnimationsEnabled(false)
tableView?.beginUpdates()
if cellType == .footer {
tableView?.reloadSections(IndexSet(integer: 0), with: .automatic)
}
tableView?.endUpdates()
UIView.setAnimationsEnabled(true)
}
}
Can anyone point me to the right direction? Thanks
Upvotes: 2
Views: 759
Reputation: 1805
Enabling & disabling animations on UIView
& invoking tableView?.beginUpdates()
simultaneously looks ambiguous.
Simply, invoking reloadSections
should work, like:
if startHeight != calcHeight {
if cellType == .footer {
tableView?.reloadSections(IndexSet(integer: 0), with: .automatic)
}
}
Upvotes: 2