繁体   English   中英

UICollectionView不显示单元格:

[英]UICollectionView not showing cells:

我正在尝试使用UICollectionView显示我的Facebook个人资料中的前10张照片。 但是,每当我运行该应用程序时,UICollectionView都不会显示任何内容-它保持黑色,并且看不到任何单元格。 (我将单元格的背景色设置为蓝色,将CollectionView的颜色设置为黑色,但我什至看不到蓝色单元格)

我正在使用SDWebImage将照片加载到单元格上。

预先感谢您的任何帮助

这是我的代码:

在我的头文件中-

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

@interface LNViewController : UIViewController <FBFriendPickerDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@end

在我的.m文件中-

#import "LNViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>

@property (weak, nonatomic) IBOutlet UICollectionView *photoCollectionView;


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self refreshArray];
    //fetch photos from facebook (this function also has [self.photoCollectionView reloadData] in it;
    [self fetchPhotosMe];
    [self.photoCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"photoCell"];
    [self.photoCollectionView reloadData];


}

#pragma Mark UICollectionView

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath  *)indexPath{
    static NSString  *identifier = @"photoCell";

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    //create array with URLs
    NSMutableArray *photosURL = [[NSMutableArray alloc] init];
    for (int i = 0; i <10; i++){
        NSDictionary *photoDic = [self.photosMeArray objectAtIndex:i];
        [photosURL addObject:[photoDic valueForKey:@"src"]];
    }

    //Load Cells
    UIImageView *photoImageView = (UIImageView *)[cell viewWithTag:100];
    [photoImageView setImageWithURL:[NSURL URLWithString:[photosURL objectAtIndex:indexPath.row]]];

    return cell;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM