CellのUIImageオブジェクトを使用するときにコレクションビューをデキューできませんでした

StackOverflow https://stackoverflow.com//questions/25012382

質問

いくつかの反復後にクラッシュした後にこのコードを実行するのに問題がある。意図された動作は、配列からコレクションビューで画像を表示することです。配列内のすべてのオブジェクトをコメントアウトすると、空のコレクションビューで実行されます。 logo.pngが存在し、ドロップダウンを通してアプリの他の部分に正しくロードできます。デリゲートとデータソースは正しくセルフに設定されています。コレクションビューには、ImageViewが表示されている(100としてタグ付けされている)単一のセルがあり、他には何もありません。画像ビューの代わりにラベルを持つと、アレイ内のすべてのオブジェクトともクラッシュが発生します。

デバッグ出力は

です

種類の視点をデキューできませんでした:識別子セルを持つUICollectionElementKindCell -

識別子にNIBまたはクラスを登録するか、ストーリーボードのプロトタイプセルを接続する

関連するコードは次のものです。

ViewController.m

#import "demo_frameworkViewController.h"

@interface demo_frameworkViewController ()

@end

@implementation demo_frameworkViewController {
    NSMutableArray *imageArray;
}


@synthesize imageArray;


- (void)viewDidLoad
{
    imageArray = [[NSMutableArray alloc] init];

    [imageArray addObject:[UIImage imageNamed:@"logo.png"]];
    [imageArray addObject:[UIImage imageNamed:@"logo.png"]];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark Collection View Methods
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

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

    return [self.imageArray count];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    UIImageView *imageDemo = (UIImageView *)[cell viewWithTag:100];

    imageDemo.image =[imageArray objectAtIndex:indexPath.row];
    [cell.layer setBorderWidth:2.0f];
    [cell.layer setBorderColor:[UIColor whiteColor].CGColor];
    return cell;


}

@end
.

ViewController.h

#import <UIKit/UIKit.h>

@interface demo_frameworkViewController : UIViewController <UINavigationControllerDelegate, UICollectionViewDelegate, UICollectionViewDataSource>


@property (nonatomic, retain) NSArray *imageArray;

@property (weak, nonatomic) IBOutlet UIImageView *imageView;


@end
.

役に立ちましたか?

解決

デバッグ出力とは、「セル」というセルが見つからないことを意味します。ストーリーボードでは、UicollectionViewがUICollectionViewが使用するセルを認識するように、UICollectionViewCellのCollection Reusable View値を 'cell'に設定する必要があります。

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