uicollectionviewでの遅延読み込み

Vix Hunk

これがレコードを表示している私のcollectionviewのコードですが、読み込みは本当にこれに遅延読み込みを実装する方法を教えてください私は私のプロジェクトにプレースホルダーの写真もあります

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MJCell" forIndexPath:indexPath];

// Setup image name
    NSString *url = [[rssOutputData objectAtIndex:indexPath.row]xmllink];
    UIImage *img = nil;
    NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
    img = [[UIImage alloc] initWithData:data];

    cell.MJImageView.image = img;
    return cell;
}

現在は機能していますが、非常に遅いです。

アミット

GCDを使用して遅延読み込みを行うのは非常に簡単です。

    // Create a queue for the operations
    dispatch_queue_t queue = dispatch_queue_create("photoList", NULL);

    // Start getting the data in the background
    dispatch_async(queue, ^{
        NSData* photoData = [NSData dataWithContentsOfURL:[NSURL URLWithString:object.photoURL]];
        UIImage* image = [UIImage imageWithData:photoData];

        // Once we get the data, update the UI on the main thread
        dispatch_sync(dispatch_get_main_queue(), ^{
           cell.photoImageView.image = image;
        });
    });

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

dispatch_syncを使用したuicollectionviewでの遅延読み込み

分類Dev

修正:SeleniumPythonでの遅延読み込み

分類Dev

QueryDSLでの遅延読み込み

分類Dev

PowerShellでの遅延読み込み?

分類Dev

要素jQueryの読み込みの遅延

分類Dev

iframeの読み込みの遅延

分類Dev

Hibernateでの動的な熱心な読み込みと遅延読み込み

分類Dev

Flutter ListViewの遅延読み込み

分類Dev

画像要素の遅延読み込み

分類Dev

Pythonの遅延読み込み

分類Dev

既存のMODX遅延読み込み

分類Dev

遅延読み込みの実装

分類Dev

DLLの遅延読み込み

分類Dev

遅延読み込みの例?

分類Dev

Firebase の遅延読み込み

分類Dev

JPA遅延読み込み

分類Dev

遅延読み込みflexslider

分類Dev

読み込みプロパティの遅延読み込み

分類Dev

UICollectionView遅延読み込みの問題。CellForIndexPathは最初のロード時にnilです

分類Dev

Meteorでの遅延読み込みの使用は何ですか?

分類Dev

Store Swiftv3での商品の読み込みの遅延

分類Dev

休止状態でのCLOBの遅延読み込み

分類Dev

SpringでのDTOフィールドの遅延読み込み

分類Dev

SQLAlchemyのcolumn_propertyでの遅延読み込み

分類Dev

TensorFlowでの遅延読み込みの実装

分類Dev

ngSwitchでの遅延読み込みのターン

分類Dev

DRFでの遅延読み込みの使用

分類Dev

SafariとWkwebviewでの遅延読み込みの問題

分類Dev

iOSCarplayでの遅延読み込みデータ