2017-10-18 163 views
1

我正在開發聊天應用程序。在我的應用程序加載早期的消息功能實施,這是不光滑和準確像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應用較早實現負載上市獲取更多的數據。

+0

loadMoreDataLoad將調用web服務加載圖像?獲取數據 –

+0

獲取表單本地數據庫.. –

+0

您應該在分頁的情況下將數據加載到'cellForRow'中請顯示'loadMoreDataLoad'方法 –

回答

0

您應該始終在CellForWowatIndexpath方法中加載數據,並且在顯示最後一個單元格時還使用分頁和加載更多數據。您可以在cellWillDisplay方法上調用加載更多方法。最後但並非最不重要的,如果要加載圖像使用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 
    } 
} 
+0

Thanx分享..但我想從頂部的Whatsapp應用程序實施.. –