我想在顯示最後一個單元格的同時向我的UITableView的底部添加一個ActivityIndicator,同時我獲取更多數據,然後在獲取數據時隱藏它。在加載時在UITableView的底部添加一個活動指示器
因此,我滾動到底部 - >顯示的最後一行 - >微調開始旋轉,而數據被提取 - >數據提取,隱藏微調 - >新的數據添加到tableview。
有關如何實現此目的的任何提示?
感謝;)
我想在顯示最後一個單元格的同時向我的UITableView的底部添加一個ActivityIndicator,同時我獲取更多數據,然後在獲取數據時隱藏它。在加載時在UITableView的底部添加一個活動指示器
因此,我滾動到底部 - >顯示的最後一行 - >微調開始旋轉,而數據被提取 - >數據提取,隱藏微調 - >新的數據添加到tableview。
有關如何實現此目的的任何提示?
感謝;)
添加此功能
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
}
}
和tableFooterView應該隱藏在數據負載。
一種方法是添加自定義單元格,在它UIActivityIndicatorView。你可以把它放在一個單獨的部分。有很多方法可以做到這一點。
或者你看看這個:https://github.com/evnaz/ENFooterActivityIndicatorView
由於屏幕尺寸不同,請勿使用修正尺寸值 – lukwuerz
什麼是tableView_category? – lukwuerz
tableview_category是包含行的默認tableView。我得到了這個和這個例子工作像一個魅力 –