简体   繁体   中英

UITableView reloadSections does not trigger viewForFooterInSection?

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

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)
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM