【发布时间】:2015-01-07 14:00:12
【问题描述】:
我希望 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];
但是给了我这个错误
无法使同类视图出队:带有标识符 cellIdentifier0 的 UICollectionElementKindCell - 必须为标识符注册一个 nib 或类或连接情节提要中的原型单元格
【问题讨论】:
-
您在哪里/何时执行注册代码循环?
-
分配collectionview后不久
-
我是在调用 cellForItem 之前注册 NSLog 吗?
-
@rounak 我没有收到日志
-
那么你的代码没有被执行。您的控制流/逻辑有问题,而不是 UICollectionView 的问题
标签: ios uicollectionview