早期加载平滑滚动

时间:2017-10-18 04:40:34

标签: ios iphone swift uitableview smooth-scrolling

我正在开发聊天应用程序。在我的应用中加载了之前实现的消息功能,该功能不像whatsapp那样流畅和准确。

我正在使用UITableview进行聊天列表并使用

获取更多数据
func scrollViewDidScroll(_ scrollView: UIScrollView) {

    if scrollView.contentOffset.y >= 0 &&  scrollView.contentOffset.y <= 50{
        print(" scrollViewDidScroll Load Earlier start- \(Utils.stringFromNSDate(Date(), inMillisec: true, useUTC: true)!)")
         if !self.messageFetcher.isHideLoadMoreDisplay{
            if self.messageFetcher.arrayOfallChatMessagesData.count > 0 && !isCheckLoading{
                self.isCheckLoading = true
                let message = self.messageFetcher.arrayOfallChatMessagesData[0]
                self.messageIdForMessageDisplay =  (message.chatMessageId )
                self.loadMoreDataLoad(threadId: self.messageFetcher.chatThreadId, isloadFromServer: false)
            }
        }
         print(" scrollViewDidScroll Load Earlier end- \(Utils.stringFromNSDate(Date(), inMillisec: true, useUTC: true)!)")
    }
}

因此,与whatspp应用程序相同,这是更好的方式来实现更早的平滑性。

1 个答案:

答案 0 :(得分:0)

您应始终在CellForWowatIndexpath方法中加载数据,并在显示最后一个单元格时使用分页并加载更多数据。您可以在cellWillDisplay方法上调用load more方法。最后但并非最不重要的是,如果您正在加载图像,请使用SDWebimage加载图像,以便滚动变得平滑

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

   // load dats here



    return cell
}

当最后一个单元格可见时重新加载数据

 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    let lastItem = self.YourArray.count - 1

        if indexPath.row == lastItem
        {
            //call load more data method
        }

    else{
        return
    }
}
相关问题