Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CollectionView与单元格重叠_Ios_Objective C_Cocoa Touch_Uikit_Uicollectionview - Fatal编程技术网

Ios CollectionView与单元格重叠

Ios CollectionView与单元格重叠,ios,objective-c,cocoa-touch,uikit,uicollectionview,Ios,Objective C,Cocoa Touch,Uikit,Uicollectionview,我的目标是在视图的页脚处有一个集合视图。单元格中充满了照片库中的照片。我不知道为什么,但细胞彼此重叠。有人知道为什么吗?以下是来自ViewController的代码: - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView

我的目标是在视图的页脚处有一个集合视图。单元格中充满了照片库中的照片。我不知道为什么,但细胞彼此重叠。有人知道为什么吗?以下是来自ViewController的代码:

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
     numberOfItemsInSection:(NSInteger)section
{

    return [self.fotoArray count];

}

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

    FotoCell *cell = [self.collectionView
                        dequeueReusableCellWithReuseIdentifier:cellIdentifier
                        forIndexPath:indexPath];

    Foto *currFoto = [self.fotoArray objectAtIndex:indexPath.row];
    // Set the selectedFotoID 
    [CoreDataManager sharedInstance].selectedFotoId = ((Foto*)[self.fotoArray objectAtIndex:indexPath.row]).objectID;
    NSURL *u = [NSURL URLWithString:currFoto.f_path];
    [self findImage:u in: cell];


    return cell;
}

// Get Photo from Asset Library
-(void)findImage:(NSURL*)u in: (FotoCell*) cell
{

    __block FotoCell *blockCell = cell;
    //
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        ALAssetRepresentation *rep = [myasset defaultRepresentation];
        CGImageRef iref = [rep fullResolutionImage];
        if (iref) {
            UIImage *largeimage = [UIImage imageWithCGImage:iref];
            //[largeimage retain];
            UIImage *thumbnail = [UIImage imageWithCGImage:iref scale:0.15 orientation:UIImageOrientationUp];
            [blockCell.fotoThumb setImage:thumbnail];
        }
    };

    //
    ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
    {
        NSLog(@"cant get image - %@",[myerror localizedDescription]);
    };



        NSURL *asseturl = u;
        ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
        [assetslibrary assetForURL:asseturl
                       resultBlock:resultblock
                      failureBlock:failureblock];

}
下面是我的Cell.m类的代码:

@implementation FotoCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}



- (void)dealloc {
    [_fotoThumb release];
    [super dealloc];
}
@end

您必须设置
UICollectionViewFlowLayout
实例的
itemSize

您必须设置
UICollectionViewFlowLayout
实例的
itemSize

我不清楚您的代码。但我以前遇到过这个问题。 原因是您在cellForItemAtIndexPath中添加了可见视图(如图像、UILabel等):

当按collectionView顺序时,滚动时所有单元格视图将重叠在一起。
您可以尝试在单元格中初始化和查看图像,然后在cellForItemAtIndexPath中设置图像名称。我不清楚您的代码。但我以前遇到过这个问题。 原因是您在cellForItemAtIndexPath中添加了可见视图(如图像、UILabel等):

当按collectionView顺序时,滚动时所有单元格视图将重叠在一起。
您可以尝试在单元格中初始化和查看图像,然后在cellForItemAtIndexPath中设置图像名称

Thanx作为答案,顺便说一句,我喜欢您的博客。。。我在我的ViewController和viewDidLoad方法中有这个:[self.collectionView注册表类:[FotoCell类]forCellWithReuseIdentifier:@“cell”];但它仍然不起作用:(UICollectionViewFlowLayout*myLayout=[[UICollectionViewFlowLayout alloc]init]autorelease];[myLayout setItemSize:CGSizeMake(48,48)];[myLayout SetCrollDirection:UICollectionViewScrollDirectionHorizontal];[self.collectionView setCollectionViewLayout:myLayout];Thanx作为答案,顺便说一句,我喜欢你的博客……我在我的ViewController和viewDidLoad方法中有这个:[self.collectionView registerClass:[FotoCell类]forCellWithReuseIdentifier:@“cell”];但它仍然不起作用:(UICollectionViewFlowLayout*myLayout=[[UICollectionViewFlowLayout alloc]init]自动释放];[myLayout setItemSize:CGSizeMake(48,48)];[myLayout setScrollDirection:UICollectionViewScrollDirection水平];[self.collectionView setCollectionViewLayout:myLayout];