Every time I reload my table by calling
tableview.reloadData()
I want to call a specification function like
myFunction()
I was wondering, instead of stacking these two function next one after another everywhere in my code like
tableview.reloadData()
myFunction()
Is there a smart and clean way of calling myFunction every time tableview reloads?
There is no delegate method to give you a callback when reloadData() has completed, but to make it cleaner you could do a couple of different things.
You could create your own function like this:
func reloadTable() {
tableView.reloadData()
myFunction()
//plus anything else you want to accomplish
}
Then you call that function everywhere in one line instead of repeating your code.
Alternatively, you could subclass UITableView
and override the reloadData() method, adding your additional functionality.
one way is to use inheritance. just implement your own tableview class and reload the reloadData function of UITableView.
class YourTableView: UITableView {
override func reloadData() {
super.reloadData()
myFunction()
}
func myFunction() {
//do something
}
}
then declare YourTableView instead of UITableView
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.