【发布时间】:2018-10-30 17:08:01
【问题描述】:
我的 tableview 有一个包含 50 多个数据的单元格列表,我不想在我的 tableView 中显示超过 50 个单元格。我只想每页显示 5 个单元格,每当我滚动时,我的页码可以增加/减少。
我想向下滚动,我的应用程序转到下一页,而我向上滚动,我的应用程序转到上一页。我该怎么做?
override func viewDidLoad() {
super.viewDidLoad()
updatePropertyListWithDistrict(district: "ABC")
}
var currentPage : Int = 1
var listLimit : Int = 5
// getting property list
func updatePropertyListWithDistrict(district: String) {
PSPWCFService.sharedClient.PropertyList(district: district, PageNumber: currentPage, PageSize: listLimit) { (json, error) in
MBProgressHUD.hide(for: self.view, animated: true)
if let error = error {
print(error.localizedDescription)
return
}
let jsonArray = json?.array
for object in jsonArray! {
let newProperty: Property = Property(json: object)
self.properties.append(newProperty)
}
self.tableView.reloadData()
if (self.properties.count == 0)
{
let alertController = UIAlertController(title: "Alert", message:
"No listings available in the area. ", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}
}
}
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
//Bottom Refresh
if scrollView == tableView{
if ((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height)
{
currentPage += 1
self.tableView.reloadData()
}
}
}
【问题讨论】:
-
我查看了它,但它没有显示当我向上/向下滚动时我将如何只显示 5 个单元格并减少/增加页码。该链接仅显示它是否向下滚动,并且在我粘贴时它不适用于我的代码
标签: ios swift uitableview pagination