Ios 是否可以使具有复杂子视图的tableview像黄油一样平滑滚动

Ios 是否可以使具有复杂子视图的tableview像黄油一样平滑滚动,ios,uitableview,Ios,Uitableview,在我的tableview中,我使用的是自定义单元格,这些单元格上有许多子视图、两个EgoImageView(imageview的子类,它获取URL并从web获取图像,然后缓存它们以供以后使用)、一个启用链接检测的textview、4个标签和一个按钮。我在egoimageview和textview中添加了点击手势。textview的高度根据其所包含文本的大小计算。高度计算是提前完成的,因此在用户滚动时,不会因为动态计算高度而影响滚动性能。所有这些数据都是从web获取的,然后在tableview作为

在我的tableview中,我使用的是自定义单元格,这些单元格上有许多子视图、两个EgoImageView(imageview的子类,它获取URL并从web获取图像,然后缓存它们以供以后使用)、一个启用链接检测的textview、4个标签和一个按钮。我在egoimageview和textview中添加了点击手势。textview的高度根据其所包含文本的大小计算。高度计算是提前完成的,因此在用户滚动时,不会因为动态计算高度而影响滚动性能。所有这些数据都是从web获取的,然后在tableview作为子视图添加之前,计算文本高度和单元格高度并将其存储在数组中。对于某些单元格,没有要显示的图像,因此在这些情况下,我只是在将egoimageview的帧设置为cgrectzero后隐藏它。这些图像在iphone屏幕上约占170像素X 100像素,每个图像约为250 KB。当我卷轴时,卷轴很不稳。我对慢速滚动单元格做了一些研究,到目前为止,我已经实现了以下功能,但性能没有显著提高:

  • 高度是预先计算好的,而不是用heightforrow方法
  • 单元格背景及其子视图的背景是不透明的
  • 数据布局有两种方式,因此我有两种类似的自定义单元格类,但有一些不同,因此根据内容,返回的单元格类型是确定的,尽管90%的情况下,只使用第一种
  • 我真的不满意这个急促的卷轴,一直沮丧地在网上寻找一些东西,让它滚动黄油光滑,尽管所有这些复杂的布局,但到目前为止没有任何帮助。请帮忙

    代码是

        - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([type intValue] == POSTS) {
        Feed *feed = [postsArray objectAtIndex:indexPath.row];
        FeedCellFormattedDataObject *feedCellFormattedDataObject=[postsCellFormattedDataArray objectAtIndex:indexPath.row];
        if(feed.feedTypeIndex==0){//SIMPLEST CELL
            SimplestCell *simplestCell=[tableView dequeueReusableCellWithIdentifier:@"simplestcell"];
            if(!simplestCell){
                simplestCell=[[SimplestCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"simplestcell"];
                simplestCell.delegate=self;
                simplestCell.isInDetailedPostView=NO;
                simplestCell.selectionStyle = UITableViewCellSelectionStyleNone;
                [simplestCell.likeBtn addTarget:self action:@selector(likeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            }
            simplestCell.cellIndex=indexPath.row;
            [simplestCell setDataWithFeed:feed andFeedCellFormattedDataObject:feedCellFormattedDataObject];
            return simplestCell;
        }
        if(feed.feedTypeIndex==1){//SIMPLEFEEDCELL WITH IMAGE
            SimpleFeedCell *simpleCellWithImage=[tableView dequeueReusableCellWithIdentifier:@"imagecell"];
            if(!simpleCellWithImage){
                simpleCellWithImage=[[SimpleFeedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"imagecell"];
                simpleCellWithImage.delegate=self;
                simpleCellWithImage.isInDetailedPostView=NO;
                UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoOrVideoTapped:)];
                [simpleCellWithImage.feedImageView addGestureRecognizer:tapGesture];
                simpleCellWithImage.selectionStyle = UITableViewCellSelectionStyleNone;
                [simpleCellWithImage.likeBtn addTarget:self action:@selector(likeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            }
            simpleCellWithImage.cellIndex=indexPath.row;
            [simpleCellWithImage setDataWithFeed:feed andFeedCellFormattedDataObject:feedCellFormattedDataObject];
            return simpleCellWithImage;
        }
    
        if(feed.feedTypeIndex==2){//SIMPLEFEEDCELL WITH VIDEO
            SimpleFeedCell *simpleCellWithVideo=[tableView dequeueReusableCellWithIdentifier:@"videocell"];
            if(!simpleCellWithVideo){
               simpleCellWithVideo=[[SimpleFeedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"videocell"];
                simpleCellWithVideo.delegate=self;
                simpleCellWithVideo.isInDetailedPostView=NO;
                UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoOrVideoTapped:)];
                [simpleCellWithVideo.feedImageView addGestureRecognizer:tapGesture];
                simpleCellWithVideo.selectionStyle = UITableViewCellSelectionStyleNone;
                [simpleCellWithVideo.likeBtn addTarget:self action:@selector(likeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
                simpleCellWithVideo.playVideoImageView.hidden=NO;
            }
            simpleCellWithVideo.cellIndex=indexPath.row;
            [simpleCellWithVideo setDataWithFeed:feed andFeedCellFormattedDataObject:feedCellFormattedDataObject];
            return simpleCellWithVideo;
        }
    
        if(feed.feedTypeIndex==3){//LINKFEEDCELL
            LinkFeedCell *linkFeedCell=[tableView dequeueReusableCellWithIdentifier:@"linkcell"];
            if(!linkFeedCell){
                linkFeedCell=[[LinkFeedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"linkcell"];
                linkFeedCell.delegate=self;
                linkFeedCell.isInDetailedPostView=NO;
                linkFeedCell.selectionStyle = UITableViewCellSelectionStyleNone;
                [linkFeedCell.likeBtn addTarget:self action:@selector(likeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
            }
            linkFeedCell.cellIndex=indexPath.row;
            [linkFeedCell setDataWithFeed:feed andFeedCellFormattedDataObject:feedCellFormattedDataObject];
            return linkFeedCell;
        }
    
    }
    else {
        EventCell * eventCell=(EventCell*)[tableView dequeueReusableCellWithIdentifier:@"eventcell"];
        if(!eventCell){
            eventCell=[[EventCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"eventcell"];
            eventCell.selectionStyle=UITableViewCellSelectionStyleGray;
        }
        [eventCell setCellDataWithEvent:[eventsArray objectAtIndex:indexPath.row]];
        return eventCell;
    }
    
    }设置数据的代码

     //set data and properties
    self.dateLabel.text=feed.when;
    self.msgTextView.text=feed.message;
    self.likesCountLabel.text=feedCellFormattedDataObject.likesString;
    self.commentsCountLabel.text=feedCellFormattedDataObject.commentsString;
    self.userImageView.imageURL=feedCellFormattedDataObject.posterPicURL;
    self.feedImageView.tag=self.cellIndex;
    self.feedImageView.imageURL=feedCellFormattedDataObject.imageURL;
    self.likeBtn.tag=self.cellIndex;
    if(feed.canUserLike){
        self.likeBtn.hidden=NO;
        [self.likeBtn setBackgroundImage:feedCellFormattedDataObject.likeButtonImage forState:UIControlStateNormal];
    }
    else self.likeBtn.hidden=YES;
    
    //adjust frames on the fly
    self.msgTextView.frame=feedCellFormattedDataObject.msgTextViewFrame;
    self.feedImageView.frame=feedCellFormattedDataObject.feedImageViewFrame;
    self.likeBtn.frame=feedCellFormattedDataObject.likeBtnFrame;
    self.likesCountLabel.frame=feedCellFormattedDataObject.likesCountLabelFrame;
    self.commentsCountLabel.frame=feedCellFormattedDataObject.commentsCountLabelFrame;
    self.commentsImageView.frame=feedCellFormattedDataObject.commentsImageViewFrame;
    self.bgView.frame=feedCellFormattedDataObject.bgViewFrame;
    

    听上去,您的tableViewCells似乎并没有那么复杂,很可能是其他原因破坏了平滑度。请添加您的CellForRowatineXpath方法,以便我们能够找出问题。您可以发布一些代码吗?特别是在您将内容加载到手机的位置。您是否尝试过使用仪器查看您的应用程序在滚动过程中的CPU时间花在哪里?它可能会指出一些简单的解决方法。有许多关于性能/响应性的优化,其中有几个专门针对表滚动问题。我添加了下面的代码,因为它太大了,无法放在这里!:)