我希望UICollection视图具有动态CellIdentifier喜欢下面。
NSString *strIdentifier = [NSString stringWithFormat:@"cellIdentifier%d",indexPath.row];
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:strIdentifier forIndexPath:indexPath];
我该怎么做?如果可能,请帮忙!!谢谢
编辑
我已经用这个代码注册了我所有的标识符
//CollectionView
self.mpCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:layout];
[self.mpCollectionView setDataSource:self];
[self.mpCollectionView setDelegate:self];
for(int i=0;i<arrayExplorerItems.count;i++)
{
NSString* strIdentifier = [NSString stringWithFormat:@"cellIdentifier%d",i];
NSLog(@"registered Id:%@",strIdentifier);
[self.mpCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:strIdentifier];
}
and my cellForItemAtIndeaxPath is
UICollectionViewCell *cell;
NSString *strIdentifier = [NSString stringWithFormat:@"cellIdentifier%d",indexPath.row];
cell = [collectionView dequeueReusableCellWithReuseIdentifier:strIdentifier forIndexPath:indexPath];
但是给我这个错误
无法将种类视图取消排队:UICollectionElementKindCell 与标识符 cellIdentifier0 - 必须为标识符注册 nib 或类,或在情节提要中连接原型单元格'
这是可能的。您需要先注册所有单元格标识符。
[collectionView registerNib:forCellWithReuseIdentifier:]
或
[collectionView registerClass:forCellWithReuseIdentifier:]
然后,您可以毫无问题地创建所有准备好的标识符并将其取消排队。