当前位置: 首页 > 知识库问答 >
问题:

显示不消耗资源的时间线

谭伟
2023-03-14
    null

取照片:

if(feedArray.count > 0){
  for(NSString *person in feedArray){
  int count = [[Globals global] getMiscPicsCountForUser:person];
  for(int i = 1; i < count; i++){
    [[Globals global] getMiscPicForUser:person :i withFetchedPicture:^(WKImage *image) {
      if(image){
        [self.thisPersonsTimelineObjects  addObject:image];
        //[self createTimelineViewForImage:image];
        NSLog(@"person: %@ -- count:%i -- temp array count:%lu -- i:%i", person, count, self.thisPersonsTimelineObjects.count ,i);
        if(self.thisPersonsTimelineObjects.count == count - 1){
          [self sortTimelineByDate];
        }
      }
    }];
  }
}

}

-(void)createTimelineViewForImage :(WKImage *)image {
  dispatch_async(dispatch_queue_create("timeline", NULL), ^{
    dispatch_async(dispatch_get_main_queue(), ^{
      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
      WKTimelineViewsViewController *view = [storyboard instantiateViewControllerWithIdentifier:@"WKTimelineViewViewController"];
      [view initWithImage:image andParentController:self];
      view.view.frame = CGRectMake(view.view.frame.origin.x,
                                   view.view.frame.origin.y,
                                   view.view.frame.size.width * 0.95,
                                   view.view.frame.size.height * 0.95);
      [self.thisPersonsTimelineViews addObject:view];
      [self.tableView reloadData];
    });
  });

}
-(void)sortTimelineByDate {
  if(self.thisPersonsTimelineObjects.count > 0){
    NSMutableArray *dateArray = [NSMutableArray array];
    for(WKImage *view in self.thisPersonsTimelineObjects){
      [dateArray addObject:[view timeStamp]];
    }
    NSMutableArray *tempArray = [NSMutableArray array];
    NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:NO];
    NSArray *descriptors = [NSArray arrayWithObject:descriptor];
    NSArray *reverseOrder = [dateArray sortedArrayUsingDescriptors:descriptors];

    for(int i = 0; i < reverseOrder.count; i++){
      NSDate *date = reverseOrder[i];
      for(int j = 0; j < self.thisPersonsTimelineObjects.count; j++){
        NSDate *timestamp = [self.thisPersonsTimelineObjects[j] timeStamp];
        if(date == timestamp){
          [tempArray addObject:self.thisPersonsTimelineObjects[j]];
        }
      }
    }
    self.thisPersonsTimelineObjects = [NSMutableArray arrayWithArray:tempArray];
    [self.thisPersonsTimelineViews removeAllObjects];
    for(WKImage *image in self.thisPersonsTimelineObjects){
      [self createTimelineViewForImage:image];
    }
  }
}

共有1个答案

爱花蜂
2023-03-14

您遇到了一个问题,因为所有的图像都是预先获取的。相反,你想要做的是在用户滚动时获取所需的图像,然后在下载时缓存它们(这是Instagram和Facebook所做的)。

首先,我建议将SDWebImage集成到您的项目中,因为它使所有这些都变得更容易。

接下来,您可以集成以下逻辑:

    null

这里有一个例子:

1和2(在数据源中):

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (!cell) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    }

    PhotoObject *object = [self objects][[indexPath row]];
    [[cell imageView] sd_setImageWithURL:[object photoURL]];

    return cell;

}

3:(表格单元格内)

-(void)prepareForReuse {

    [super prepareForReuse];

    [[self imageView] sd_cancelCurrentImageLoad];
    [[self imageView] setImage:nil];

}
 类似资料:
  • 问题内容: 我的问题: 当线程处于状态(非休眠)> 99.9%的时间时,JVM中的大量线程是否会消耗大量资源(内存,CPU)吗?当线程正在等待时,如果根本需要维护它们,需要花费多少CPU开销? 答案是否也适用于与非JVM相关的环境(例如linux内核)? 内容: 我的程序收到大量占用空间的程序包。它在不同的程序包中存储相似属性的计数。在收到包裹后的给定时间(可能是数小时或数天)之后,该特定包裹将过

  • 问题内容: 我发现从Java应用程序填充报告时,JasperReports确实很 慢 。程序挂在此行: 它通常在那里停留 3分钟,消耗高达300Mb的RAM和50%的CPU 。 是使用3个子报表的已编译(.jasper)报告。 数据源是一个很大的XML文件(大约10万行,1.5Mb) 该机器是具有4Gb RAM的3Ghz双核 那么,如何改善报表填充性能? 问题答案: 问题 看来问题出在XPath引

  • 我有一个问题,我认为optaplanner可能能够解决,但我还没有看到一个演示,非常适合我要做的。我的问题集是为测试床安排物联网节点的使用。每个测试执行(作业)需要在其将使用的节点上设置不同的约束。例如,一个作业可能要求M个节点具有资源a,N个节点具有资源B。它还将指定它需要节点的时间长度和作业开始的窗口。为了成功地安排作业,它必须能够申请足够的资源来满足作业特定的要求(即硬限制)。 作为opta

  • 我正在我的GTX 1060 6gb上使用Python中的Tensorflow 1.2训练LSTM。 在每个时代,我用这种方法保存模型: 一切正常,但在九个时代之后,当我试图用这种方法保存模型时,我得到了ResourceExhaustedError。 我在培训期间检查了我的资源,但没有耗尽任何资源。 我得到的错误如下: 2017-06-29 12:43:02.865845: W tenstorflo

  • 具有特定组id的使用者连接到代理,监听主题不到1分钟,然后断开连接(根据业务逻辑)。当它监听主题时,它可以使用一些消息。当同一个使用者重复这个动作时,它会使用相同的消息! 我发现Kafka用间隔1分钟保存偏移。这意味着消费者必须听超过1分钟的主题。我怎样才能缩短这个间隔? 我发现了这样的属性: null null

  • 问题内容: 我正在尝试显示时间戳记- 我尝试了不同的查询方式,并且还尝试将用作值。似乎没有任何作用。我的目的是让该应用显示以前的素数和它们被发现的时间。该应用程序的初衷是让用户能够关闭/杀死该应用程序,并在重新启动该应用程序时从上次找到的素数恢复计数。如果您有任何暗示,我也将不胜感激。 这是PrimeDBManager类 头等舱 最后是MainActivity类 问题答案: 好的,既然您上传了项目