Прокрутите вниз TableView с пользовательским разделом и ячейкой Swift. - PullRequest
0 голосов
/ 10 апреля 2020

Мой tableview имеет пользовательские sections и cells. Каждый раз, когда пользователь прокручивает страницу до конца, он вызывает сервер и загружает дополнительные данные. Моя проблема в том, как определить последний section, чтобы он мог загрузить больше данных? Каждый section содержит от 1 до 3 rows. Мой willDisplay не работал должным образом, и индикатор refreshControl.beginRefreshing() тоже не показывался. Спасибо!

let refreshControl = UIRefreshControl()

//MARK - Header Sections
func numberOfSections(in tableView: UITableView) -> Int {
    return tableData[segmentedControlIndex].count
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 40
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell") as! HomeSectionTableViewCell

    let model = events[segmentedControlIndex][section]
    cell.setup(model: model)

    .
    .
    .

    return cell.contentView
}

//MARK - Cells
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return tableData[segmentedControlIndex][section].rows.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "detailCell") as! HomeTableViewDetailCell

    .
    .
    .

    cell.detailTitleLabel?.text = tableData[segmentedControlIndex][indexPath.section].rows[indexPath.row].detailTitleLabelString
    cell.detailSubtitleLabel?.text = tableData[segmentedControlIndex][indexPath.section].rows[indexPath.row].detailSubtitleLabelString

    return cell
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 0.000001
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if let cell: HomeTableViewDetailCell = tableView.cellForRow(at: indexPath) as? HomeTableViewDetailCell {
        cell.detailTitleLabel?.numberOfLines = cell.detailTitleLabel?.numberOfLines == 0 ? 1 : 0            
        tableView.reloadData()
    }
}

//MARK - TableView add more data
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if indexPath.section == tableView.numberOfSections - 1 {
        self.refreshControl.beginRefreshing()
        self.page = self.page + 1
        self.getMoreData() { result in
            self.refreshControl.endRefreshing()
            print("Load More Bets Data reload: \(result == true ? "Success":"Failure")")
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...