ios - Determine if a cell in on screen and perform a function -
i want find out if cell displaying onscreen in table view.
i tried out willdisplay
method it's of no use. tried
if (tableview.indexpathsforvisiblerows?.contains(indexpath))! { print("showing now") }
function works, doesn't print when cell on screen or scroll down. ex: if have 5 cells, app launches , cell on display, nothing printed. also, when scroll cells 1 5, nothing displayed. on contrary, if scroll cells 5 1, display it, defies purpose.
i hope understood query , can me apt solution.
cheers!
willdisplay
method of tabview should work you.
give datasource
, delegate
properly. control+drag
tableview
yellow icon display correct options.
add extension viewcontrollerclass
, confirm table protocols-:
extension viewcontroller : uitableviewdelegate,uitableviewdatasource{ func numberofsections(in tableview: uitableview) -> int { return 1 }// default 1 if not implemented func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int{ return 2 } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell{ let cell = tableview.dequeuereusablecell(withidentifier: "cell") cell?.textlabel?.text = indexpath.row return cell! } // display prints while displaying cells func tableview(_ tableview: uitableview, willdisplay cell: uitableviewcell, forrowat indexpath: indexpath) { print("visible now") }
Comments
Post a Comment