我有一个表格视图,有时我会得到 1000 或 40 甚至有时甚至 4 个值,但我希望当我得到超过 100 个值时,我想以 10 - 10 的滚动显示我的数组。
向上滚动表格视图,我需要在向上滚动 10 行后暂停滚动,使用此代码会出错,我的数组在 [Any] 中,并且想要像 Facebook 和 instagram 一样滚动
我想先把我的数组分成 10 行,然后我可以追加下 10 行。
var allUserArray = [Any]()
override func viewDidLoad() {
super.viewDidLoad()
var index = allUserArray.first
while index < limit {
allUserArray.append(index)
index = index + "1"
}
}
extension AdvanceSearchViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return allUserArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "advanceSearch") as! AdvanceSearchTableViewCell
let userData = allUserArray[indexPath.row] as! [String: Any]
let dob = userData["dob"] as! String
let age = self.getAgeFromDate(dob: dob)
let photo1 = userData["photo1"] as? String
let height = userData["Height"] as? String ?? "null"
let religion = userData["Religion"] as? String ?? "null"
cell.userNameLabel.text = "HM- \(userData["ProfileID"] as! String)"
cell.userProfessionLabel.text = userData["Profession"] as? String ?? "null"
cell.userAgeLabel.text = "\(age), \(height), \(religion)"
if let profileImage = photo1 {
urlStringOne = "\(USER_IMAGE_BASE_URL)\(profileImage)"
} else {
if (UserDefaults.standard.value(forKey: "gender") as! String == "Female") {
urlStringOne = "\(USER_IMAGE_URL_MALE)"
} else {
urlStringOne = "\(USER_IMAGE_URL_FEMALE)"
}
}
loadImage(urlStringOne, cell)
return cell
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if self.allUserArray.count != nil {
self.totalEnteries = self.allUserArray.count
print("idealist/\(self.allUserArray.count)")
print("total123/\(self.totalEnteries)")
var entries = allUserArray.count - 1
print("total-00/\(entries)")
If indexPath.row == entries {
print("(----------)")
if allUserArray.count < totalEnteries {
var index = allUserArray.count as! String
self.limit = index + "20"
while index < self.limit {
self.allUserArray.append(index)
index = index + "1"
}
self.perform(#selector(self.loadTable), with: nil, afterDelay: 2.0)
}
}
}
}
@objc func loadTable() {
self.advanceSearchTableView.reloadData()
}
}