2

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

Joe L
  • 83
  • 1
  • 2
  • 7

1 Answers1

2

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)
        }
    }
ystack
  • 1,785
  • 12
  • 23
  • Thanks @ystack. I tried that, and it makes no difference :( – Joe L Mar 03 '17 at 03:48
  • woah! Have you tried performing a simple `table.reloadData()`? – ystack Mar 03 '17 at 21:39
  • reloadData would probably redraw the footer. But I'm really looking for an elegant way of update the section footer without reload entire table, reload also cause keyboard to dismiss, which I don't want while user is typing. – Joe L Mar 04 '17 at 02:24