Loading images in background to optimize the loading in ios

后端 未结 9 1269
星月不相逢
星月不相逢 2021-02-02 03:02

I am trying to optimize the load in my application, in fact, I have a lot of images that loaded in my application, and I spend a lot of time waiting for a view controller to ope

9条回答
  •  庸人自扰
    2021-02-02 03:42

    Yes, you can add placeholder image to it.

    It will not slow down the scrolling and will load image accordingly with time.

    Also import this file UIImageView+WebCache.m and MapKit Framework

    Here is the link to download the files.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
         static NSString *CellIdentifier = @"Cell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
            }
        UIImageview*  iV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
       [iV setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"image_placeholder.gif"]];
       [cell.contentView addSubview:iV];
       [iV release];
    
    }
    

    Just clean, build and run.

提交回复
热议问题