테이블보기가 맨 아래에 도달하면 SQL Server에서 반환 된 더 많은 결과를로드하는 메서드를 구현하고 있습니다.Swift tableview 더 많은 데이터로드
내가 직면 한 문제는 getData() 메서드가 루프에서 호출되어 그 이유를 파악할 수 없다는 것입니다. 응용 프로그램이 종료 될 때까지
로그 출력 아래 반복 :
인덱스 경로 : 12
마지막 요소 : 12
인덱스 경로 : 12
마지막 요소 : 12
나는 루프를 만드는 그 중 하나를 의심하지만 변경해야할 것을 해결할 수는 없다.
이 가진 모든 도움을 많이
을 감사이 내 willDisplayCell 방법입니다 :func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastElement = id.count - 1
if indexPath.row == lastElement {
print("Index Path:\(indexPath.row)")
print("Last Element: \(lastElement)")
limitf = "\(lastElement)"
getData()
}
}
내가 데이터를 얻기 위해 사용하고있는 기능 :
func getData(){
let defaults = UserDefaults.standard
let userID = defaults.string(forKey: "id")
if(limitf == ""){
id.removeAll()
firstname.removeAll()
lastname.removeAll()
fbid.removeAll()
image.removeAll()
totalratings.removeAll()
mobile.removeAll()
}
let url = NSURL(string: "https://www.****/getapplications.php?&jobid=\(jobid)&limitf=\(limitf)")
// print(url!)
let task = URLSession.shared.dataTask(with: url as! URL) { (data, response, error) -> Void in
if let urlContent = data {
do {
if let jsonResult = try JSONSerialization.jsonObject(with: urlContent, options: []) as? [[String:AnyObject]] {
var i = 0
while i < jsonResult.count {
self.id.append(jsonResult[i]["id"]! as! String)
self.firstname.append(jsonResult[i]["firstname"]! as! String)
self.lastname.append(jsonResult[i]["lastname"]! as! String)
self.fbid.append(jsonResult[i]["fbid"]! as! String)
self.image.append(jsonResult[i]["image"]! as! String)
self.totalratings.append(jsonResult[i]["totalratings"]! as! String)
self.mobile.append(jsonResult[i]["mobile"]! as! String)
i = i + 1
}
}
} catch {
print("JSON serialization failed")
}
} else {
print("ERROR FOUND HERE")
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
task.resume()
}
}
플래그가 프로세스가 이미 실행 중임을 나타내는 경우 단순히 반환하도록 'getData'가 실행 중일 때 검색 할 플래그를 추가하려고 시도 했습니까? 이런 식으로,'getData'가 연속적으로 두 번 호출된다면, 그것은 한 번만 실행될 것입니다. – Fahim