質問

現在このコードを使用して左側のサムネイル、タイトル、字幕でテーブルをロードしています。

- (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];
    }

    NSDictionary *post           = [posts objectAtIndex:indexPath.row];

    cell.textLabel.text       = [post objectForKey:@"post_text"];
    cell.detailTextLabel.text = [post objectForKey:@"post_author_name"];

    NSString *postpictureUrl = [post objectForKey:@"picture"];
    NSData   *data           = [NSData dataWithContentsOfURL:[NSURL URLWithString:postpictureUrl]];

    cell.imageView.image = [UIImage imageWithData:data];

    return cell;
}
.

もちろん、これは私がここでやっている同期荷重のために生産では機能しません。

このような状況における非同期荷重のためのあなたの提案は何ですか?

AFネットワーク(まだ使用していません)が見つかりました。この問題への軽量アプローチ

役に立ちましたか?

解決

AsyncImageViewはあなたの友達です、それをチェックしてください。

imageURLを設定してください。

他のヒント

Use lazy loading in table view
Use this code


    (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];
        }

        NSDictionary *post = [posts objectAtIndex:indexPath.row];

        cell.textLabel.text = [post objectForKey:@"post_text"];
        cell.detailTextLabel.text = [post objectForKey:@"post_author_name"];
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,  0ul);
        dispatch_async(queue, ^{
         //This is what you will load lazily
      NSString *postpictureUrl = [post objectForKey:@"picture"];
        NSData   *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:postpictureUrl]];
            dispatch_sync(dispatch_get_main_queue(), ^{

        cell.imageView.image = [UIImage imageWithData:data];
                [cell setNeedsLayout];
      }); 
}); 

        return cell;
    }
.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top