ios - Scroll UITableViewCell visible and highlight it -
i have following setup: uitableview leads (when user selects cell) uipageviewcontroller, user can scroll same items presented in uitableview without going , selecting item.
when user go back, want scroll last viewed item in uipageviewcontroller , highlight it, user knows better (s)he is.
using tableview:scrolltorowatindexpath:atscrollposition:animated: can scroll last viewed cell, , tableview:selectrowatindexpath:animated:scrollposition: , tableview:deselectrowatindexpath:animated, can highlight cell. haven't figured out nice, clean way both @ same time, is, first scroll , highlight cell.
here current working, hacky solution, break down:
if let visible = tableview.indexpathsforvisiblerows { if !visible.contains(indexpath) { // cell not visible, scroll required tableview.scrolltorowatindexpath(indexpath, atscrollposition: .middle, animated: true) // highlight cell after 0.4 seconds (aka after scroll animation) let delaytime = dispatch_time(dispatch_time_now, int64(0.4 * double(nsec_per_sec))) dispatch_after(delaytime, dispatch_get_main_queue()) { self.tableview.selectrowatindexpath(indexpath, animated: true, scrollposition: .none) self.tableview.deselectrowatindexpath(indexpath, animated: true) } } else { // no need scroll, highlight tableview.selectrowatindexpath(indexpath, animated: true, scrollposition: .none) tableview.deselectrowatindexpath(indexpath, animated: true) } } is there nicer way of doing this, without relying on hard-coded timing?
Comments
Post a Comment