简体   繁体   English

加载较早,滚动流畅

[英]Load Earlier With smooth scroll

I am working on chat application. 我正在研究聊天应用程序。 In my app load earlier message feature implemented which is not smooth and accurate like whatsapp . 在我的应用程序加载中,实现了较早的消息功能,该功能不像whatsapp那样流畅,准确。

I am using UITableview for chat listing and fetching more data using 我正在使用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)!)")
    }
}

So, Which is better way to achieve load earlier with smoothness same as like whatspp Application. 因此,与whatspp应用程序一样,哪种方法可以更早地实现平滑加载是更好的方法。

You should always load your data in CellForWowatIndexpath method, and also use pagination and load more data when that last cell is displayed. 您应该始终在CellForWowatIndexpath方法中加载数据,还应使用分页并在显示最后一个单元格时加载更多数据。 You can call load more method on cellWillDisplay method. 您可以在cellWillDisplay方法上调用load more方法。 And last but not least if you are loading images use SDWebimage to load the image so that the scrolling becomes smooth 最后但并非最不重要的一点是,如果要加载图像,请使用SDWebimage加载图像,以使滚动变得流畅

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

   // load dats here



    return cell
}

Reload the data when last cell is visible 当最后一个单元格可见时重新加载数据

 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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM