iOS Tableview Feed显示在Facebook [滚动问题]

时间:2016-06-30 13:36:29

标签: ios swift scroll tableview feed

我创建的应用程序显示了Facebook中的提要,其中包括赞,评论计数和最近的评论

它工作正常,但滚动时不顺畅,它会像混蛋[Stops and Scrolls]滚动

我搜索谷歌这个,我找到了以下参考文献

objective c UITableView not scrolling smooth with custom cell & views

我使用Cache来存储加载的图像,如果可用,则从缓存中重新获取它们

http://www.cocoawithlove.com/2010/03/load-from-nib-or-construct-views-in.html

我通过代码和UITableViewCell文件(从nib加载)XIB创建了reuseidentifier来检查速度,但两者都相同

有人可以建议我怎样才能顺利滚动, 或者有没有其他方法可以将View视为Facebook Feeds

//MyFeedClass
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = self.postsList.dequeueReusableCellWithIdentifier("FeedPostDisplay") as! FeedPostDisplay;
        let temp_feed = feeds[indexPath.section];
        cell.delegate = self;
        cell.configureCell(temp_feed, index: indexPath.section, is_add_photos: is_add_photos);
        return cell;
    }
//UITableViewCellClass    
func configureCell(feedData: Feed, index: Int, is_add_photos: Bool){
            feedAuthorBtn.tag = index;
            feedImageBtn.tag = index;
            commentAuthorsBtn.tag = index;
            likeBtn.tag = Int(feedData.id)!;
            commentBtn.tag = index;
            settingBtn.tag = index;


            //Feed Profile Image
            if(!feedData.user.user_media.profile_pics.large.isEmpty)
            {
                let placeholder = UIImage(view: loadingView(CGSizeMake(feedAuthor.frame.width, feedAuthor.frame.height)));
                feedAuthor.load(feedData.user.user_media.profile_pics.large, placeholder: placeholder){ URL, image, error, cacheType, identity in
                    if cacheType == CacheType.None {
                        let transition = CATransition()
                        transition.duration = 0.5
                        transition.type = kCATransitionFade
                        self.feedAuthor.layer.addAnimation(transition, forKey: nil)
                        self.feedAuthor.image = image;
                        self.feedAuthor.clipsToBounds = true;
                    }
                }
                feedAuthor.layer.cornerRadius = feedAuthor.frame.width/2;
                feedAuthor.contentMode = .ScaleAspectFill;
                feedAuthor.clipsToBounds = true;
            }
            else
            {
                feedAuthor.image = UIImage(view: noPicView(CGSizeMake(feedAuthor.frame.width, feedAuthor.frame.height)));
            }

            feedAuthorName.text = feedData.user.username;

            let dateFormatter = NSDateFormatter();
            dateFormatter.dateFormat = "MMMM d";
            feedDate.text = dateFormatter.stringFromDate(feedData.timestamp);

            //Feed Image
            if !feedData.post_media[0].large.isEmpty
            {
                let placeholder = UIImage(view: loadingView(CGSizeMake(feedImage.frame.width, feedImage.frame.height)));
                feedImage.load(feedData.post_media[0].large, placeholder: placeholder){ URL, image, error, cacheType, identity in
                    if cacheType == CacheType.None {
                        let transition = CATransition()
                        transition.duration = 0.5
                        transition.type = kCATransitionFade
                        self.feedImage.layer.addAnimation(transition, forKey: nil)
                        self.feedImage.image = image;
                        self.feedImage.clipsToBounds = true;
                    }
                }
                feedImage.contentMode = .ScaleAspectFill;
                feedImage.clipsToBounds = true;
            }

            //Feed Like Image
            likeImage.image = UIImage(named: "like.png");
            if feedData.post_is_liked
            {
                likeImage.image = UIImage(named: "like-selected.png");
            }

            //Feed Likes Count
            likesCount.text = feedData.post_likes_count;


            //Feed Comments Count
            commentsCount.text = feedData.post_comments_count;


            if(!feedData.post_recent_comments.user.user_media.profile_pics.large.isEmpty)
            {
                let placeholder = UIImage(view: loadingView(CGSizeMake(commentAuthorsImage.frame.width, commentAuthorsImage.frame.height)));
                commentAuthorsImage.load(feedData.post_recent_comments.user.user_media.profile_pics.large, placeholder: placeholder){ URL, image, error, cacheType, identity in
                    if cacheType == CacheType.None {
                        let transition = CATransition()
                        transition.duration = 0.5
                        transition.type = kCATransitionFade
                        self.commentAuthorsImage.layer.addAnimation(transition, forKey: nil)
                        self.commentAuthorsImage.image = image;
                        self.commentAuthorsImage.clipsToBounds = true;
                    }
                }
                commentAuthorsImage.contentMode = .ScaleAspectFill;
            }
            else
            {
                if !feedData.post_recent_comments.id.isEmpty
                {
                    commentAuthorsImage.hidden = false;
                    commentAuthorsImage.image = UIImage(view: noPicView(CGSizeMake(commentAuthorsImage.frame.width, commentAuthorsImage.frame.height)));
                }
                else
                {
                    commentAuthorsImage.hidden = true;
                }
            }
            commentAuthorsImage.layer.cornerRadius = commentAuthorsImage.frame.width/2;
            commentAuthorsImage.clipsToBounds = true;
            commentAuthorsName.text = feedData.post_recent_comments.user.username;
            commentText.text = feedData.post_recent_comments.comment;
        }`

0 个答案:

没有答案