我添加了UICollectionView
到view中。然後報錯了。
錯誤:
"NSInvalidArgumentException', reason: '-[NSIndexPath reuseIdentifier]: unrecognized selector sent to instance"
方法:
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"CellID";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *imageView = (UIImageView *)[cell viewWithTag:10];
imageView.image = [UIImage imageNamed:@"V.jpg"];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
你如果是代碼創建的話 要注冊cell kcellID是你的identifier
[collectionView registerClass:[Cell class] forCellWithReuseIdentifier:kCellID];
如果是storyboard創建的話
在storyboard中選中cell 把 view cell中有個identifier改成你的identifier
你試試看