изображения не отображаются плавно после вызова tableview prefetchRowsAt - PullRequest
0 голосов
/ 30 января 2020

Я показываю изображения в Tableview, я использовал метод Tableview prefetchRowsAt для плавного отображения изображений, но Tableview изображения показывают небольшое отставание (рывок) после Tableview prefetchRowsAt.

Мне не ясно, где я должен изменить, чтобы получить результат. Я должен правильно показывать изображения в Tableview без задержек и рывков. Я не нашел никакого решения.

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            if let dict = self.listArray[indexPath.row] as? Dictionary<String,AnyObject>
            {
                customModel = dict
                let feedModal = FeedListModal(dict)
                return self.loadimages(feedModal: feedModal, isPost: true)
        }}

    func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
            for indexPath in indexPaths {
                   print("prefetchRowsAt.row",indexPath.row)
                   if let dict = self.listArray[indexPath.row] as? Dictionary<String,AnyObject>{
                   customModel = dict
                    DispatchQueue.main.async {
                        let feedModal = FeedListModal(dict)
                       self.loadimages(feedModal:feedModal, isPost: true)
                    }
           }
       }
    }

@discardableResult func loadimages(feedModal : FeedListModal, isPost : Bool) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "PostOfferTableViewCell") as! PostOfferTableViewCell
        cell.feedPOBusinessNameLabel.text = feedModal.BusinessName
        cell.feedPOImage.sd_setImage(with: URL(string: feedModal.ImageUrl), placeholderImage: UIImage(named: "placeholder"))
        cell.businessLogoImage.sd_setImage(with: URL(string: feedModal.BusinessLogoUrl), placeholderImage: UIImage(named: "placeholder"))
        cell.selectionStyle = .none
        return cell
    }


 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cellHeightDictionary.setObject(cell.frame.size.height, forKey: indexPath as NSCopying)
        if (indexPath as NSIndexPath).row == self.listArray.count-1
        {
             var cellHeights = [IndexPath: CGFloat]()
             cellHeights[indexPath] = cell.frame.size.height
            if let dict = self.listArray[indexPath.row] as? Dictionary<String,AnyObject>
               {
                   customModel = dict
                    DispatchQueue.main.async(execute: {
                    let feedModal = FeedListModal(dict)
                    self.loadimages(feedModal: feedModal, isPost: true)
                    })
               }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...