I am trying to implement a pull to refresh functionality in a ViewController which contains a TableView. Currently, the TableView is displaying stories from a data source which contains the following stories [A, B, C, D]
When I pull to refresh, I get three new stories from server : [D, E, F] now I have to display the stories in this order [D, E, F, A, B, C]
override func viewDidLoad() { super.viewDidLoad() let refreshControl = UIRefreshControl() refreshControl.addTarget(self, action: #selector(loadItems), for: .valueChanged) self.refreshControl = refreshControl } @objc func loadItems() { // confused here tableView.reloadData() refreshControl?.endRefreshing() } override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return alphabet.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = alphabet[indexPath.row] return cell }
https://stackoverflow.com/questions/66792329/pull-to-refresh-for-new-items-in-swift March 25, 2021 at 10:45AM
没有评论:
发表评论