UITableView缓存

UITableView缓存,uitableview,caching,tableview,Uitableview,Caching,Tableview,我创建了一个UITableView,数据通过一个JSON文件传输,非常繁重,我想知道是否有可能将tableView缓存起来,例如,每个segue push? 我会将我的tableView缓存放在加载速度更快的位置加载此页面 我的条目JSON YouTube API v3: - (void)fetchEntries { NSString *searchURL = [API_V3_CHANNEL_URL stringByAddingPercentEscapesUsingEncoding:NS

我创建了一个UITableView,数据通过一个JSON文件传输,非常繁重,我想知道是否有可能将tableView缓存起来,例如,每个segue push? 我会将我的tableView缓存放在加载速度更快的位置加载此页面

我的条目JSON YouTube API v3:

- (void)fetchEntries
{
    NSString *searchURL = [API_V3_CHANNEL_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSData *searchData = [NSData dataWithContentsOfURL:[NSURL URLWithString:searchURL]];
    NSDictionary *searchDict =[NSJSONSerialization JSONObjectWithData:searchData options:NSJSONReadingMutableContainers error:nil];
    self.readArray = [searchDict objectForKey:@"items"];
}
和我的tableview代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";

    YouTubeCell *cell = (YouTubeCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Add utility buttons, si besoin effacer de ici
    NSMutableArray *leftUtilityButtons = [NSMutableArray new];

    [leftUtilityButtons sw_addUtilityButtonWithColor:
     UIColorFromRGB(0x2c3e50)
                                                icon:[UIImage imageNamed:@"Icon-message-swipe"]];
    [leftUtilityButtons sw_addUtilityButtonWithColor:
     UIColorFromRGB(0x475198)
                                                icon:[UIImage imageNamed:@"IconFacebook2"]];
    [leftUtilityButtons sw_addUtilityButtonWithColor:
     UIColorFromRGB(0x4EA5EC)
                                                icon:[UIImage imageNamed:@"IconTwitter2"]];
    [leftUtilityButtons sw_addUtilityButtonWithColor:
     UIColorFromRGB(0xe74c3c)
                                                icon:[UIImage imageNamed:@"IconYoutube3"]];

    cell.leftUtilityButtons = leftUtilityButtons;
    cell.delegate = self;

    // à ici


    NSDictionary *searchResult = [self.readArray objectAtIndex:indexPath.row];

    //Create the button and add it to the cell
    //UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //[button addTarget:self
    //         action:@selector(customActionPressed:)
    //forControlEvents:UIControlEventTouchDown];
    //[button setTitle:@"Custom Action" forState:UIControlStateNormal];
    //button.frame = CGRectMake(150.0f, 5.0f, 150.0f, 30.0f);
    //[cell addSubview:button];

    cell.ytTitle.text = [[searchResult objectForKey:@"snippet"] valueForKey:@"title"];

    cell.ytLink.text = [[[searchResult objectForKey:@"snippet"] objectForKey:@"resourceId"] valueForKey:@"videoId"];

    cell.ytLink.hidden = true;

    cell.ytTitle.font = [UIFont fontWithName:@"BigNoodleTitling" size:17];

    NSString *imageHD = [[[[searchResult objectForKey:@"snippet"] objectForKey:@"thumbnails"] objectForKey:@"high"] valueForKey:@"url"];


    NSURL *imageURL = [NSURL URLWithString:imageHD];
    NSString *key = imageHD;
    NSData *data = [ISCache objectForKey:key];
    if (data) {
        UIImage *image = [UIImage imageWithData:data];
        cell.ytThumbnail.image = image;
    } else {
        cell.ytThumbnail.image = [UIImage imageNamed:@"hqdefault.jpg"];
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
        dispatch_async(queue, ^{
            NSData *data = [NSData dataWithContentsOfURL:imageURL];
            [ISCache setObject:data forKey:key];
            UIImage *image = [UIImage imageWithData:data];
            dispatch_sync(dispatch_get_main_queue(), ^{
                cell.ytThumbnail.image = image;
            });
        });
    }

    return cell;
}

这是给Objective-C的吗?你还没有指定语言…rafrachisse=刷新,我想…你能发布一些代码,以便我们更好地了解你在寻找什么吗?是的,对不起,我的英语说得不好,这是刷新是的,语言是我给你的一些代码的目标CI: