ios - UITableViewCell Not Autoresizing in "Live" Search -
little bit of background
i in process of making search feature announcements in app. load initial announcements in uitableview
custom cell display. achieve dynamic cell size in viewdidload()
method of announcementtableviewcontroller
class use autoresizing technique:
tableview.estimatedrowheight = tableview.rowheight tableview.rowheight = uitableviewautomaticdimension
that works displaying cells various heights. calling tableview.reloaddata()
when refreshing cells' data works great.
i have different uitableview
displays blank tableview , uisearchbar
header. implement uisearchbardelegate
method searchbar(_:textdidchange:)
, perform search filter logic , append filtered announcements filteredannouncements
array.
i call tableview.reloaddata()
method in didset
filteredannouncements
.
the issue
when type in search bar cells not automatically resize themselves, in fact default height. have title , body each announcement, body gets cut off.
what i've tried
the uitableautomaticdimension
trick doesn't seem work live search (that updates after each keypress). i've tried calling tableview.setneedsdisplay()
, tableview.setneedsupdatedconstraints
, tableview.setneedslayout()
in didset
observer of filteredannouncements
array.
i've tried override didmovetosubview()
method in custom cell's class call different methods named above per old stackoverflow question, no luck.
edit: answered own question below
calling beginupdates
, endupdates
on table force recalculate heights rows.
i think you'll find whole experience easier (and more pleasing users!) if implement row insertion/deletion methods of uitableview
instead of using reloaddata
.
Comments
Post a Comment