Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return UITableViewAutomaticDimension
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return array.count;
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "xxxxx", for:indexPath) as! xxxxxxxx
- return cell;
- }
- func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
- if scrollView == tableView {
- if ((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height) {
- print("Scroll Ended")
- fetchDataFromApi()
- }
- }
- }
- func fetchDataFromApi() {
- let jsonUrlString = "xxxxxxx"
- guard let url = URL(string: jsonUrlString) else {
- return
- }
- print(url)
- URLSession.shared.dataTask(with: url) {(data,response,err) in
- guard let data = data else {
- return
- }
- do {
- let apiResponseData = try JSONDecoder().decode(ApiResponse.self, from: data)
- if apiResponseData.httpStatusCode == HttpStatusCode.OK {
- if let apiResponse = apiResponseData.data{
- self.array.append(contentsOf: apiResponse)
- }
- DispatchQueue.main.async {
- self.tableView.reloadData()
- }
- }
- else {
- print("API Response Error : (apiResponseData.httpStatusCode) (apiResponseData.errorMessage)")
- }
- }catch let jsonErr {
- print("Serialization Error (jsonErr)")
- }
- }.resume()
- }}
Add Comment
Please, Sign In to add comment