при разбивке на страницы новые данные были добавлены в табличное представление, которое прокручивает время просмотра таблицы в IOS swift - PullRequest
0 голосов
/ 13 ноября 2018
 var cellHeights: [IndexPath : CGFloat] = [:]

 func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    guard let height = cellHeights[indexPath] else { return 260.0 }
    return height
 }

 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    cellHeights[indexPath] = cell.frame.size.height
    let lastCell = self.ScrollArray.count - 3
    if IsLastMessage == 0 {
        if indexPath.row == lastCell {
            IsPageNo = IsPageNo + 1
            UpdateScrollAPI()
        }
    }
 }

Я пробовал приведенный выше код, но не нашел решения, пожалуйста, помогите мне с этим.

1 Ответ

0 голосов
/ 13 ноября 2018

Привет, смотрите ниже, как я это сделал.Работает нормально.

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

        if indexPath.row == arrModel.count - 1 && pageNo != -1
        {
            // this is last cell
            self.loadMoreData(withLoader: true)
        }
        return cell
    }

При вызове API для загрузки дополнительных данных PageNo может управляться следующим образом:

if arrData.count < Int(rowsPerPage)!
{
    pageNo = -1
}
else
{
    pageNo += 1
}
...