I want to add a ActivityIndicator to the bottom of my UITableView when the last cell is displayed, while I'm fetching more data, then when the data got fetched hide it.
So I scroll to the bottom -> last row displayed -> spinner starts spinning while data is fetched -> Data fetched, hide the spinner -> new data added to the tableview.
Any tips on how can I achieve this?
Thanks ;)
Adding Search Bar on TableView Add the UISearchBar at the top of your UITableView. … and give the name searchBar. In the ViewController add a Boolean called searching to know when to switch between the full list of items and the list of items from the searching results.
yes it is possible, I added the UITableVIew within the UITableView cell .. :) no need to add tableview cell in xib file - just subclass the UITableviewCell and use the code below, a cell will be created programatically.
There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.
Add This Function
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { let lastSectionIndex = tableView.numberOfSections - 1 let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1 if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex { // print("this is the last cell") let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray) spinner.startAnimating() spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: tableView.bounds.width, height: CGFloat(44)) self.tableview.tableFooterView = spinner self.tableview.tableFooterView?.isHidden = false } }
and tableFooterView should hide when data load.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With