Ios 带有动态单元格标识符的UICollectionView
我希望UICollection视图具有动态CellIdentifier 就像跟在后面一样Ios 带有动态单元格标识符的UICollectionView,ios,uicollectionview,Ios,Uicollectionview,我希望UICollection视图具有动态CellIdentifier 就像跟在后面一样 NSString *strIdentifier = [NSString stringWithFormat:@"cellIdentifier%d",indexPath.row]; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:strIdentifier forIndexPa
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];
//CollectionView
self.mpCollectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0,0,frame.size.width,frame.size.height)collectionview布局:布局];
[self.mpCollectionView setDataSource:self];
[self.mpCollectionView setDelegate:self];
对于(int i=0;i是可能的。您需要首先注册所有单元格标识符
[collectionView registerNib:forCellWithReuseIdentifier:]
或
然后,您就可以创建所有准备好的标识符并将其出列。我如何注册不同的标识符?您在哪里/何时执行注册代码循环?分配CollectionView后不久,您是否在调用cellForItem之前获得要注册的NSLog?@rounak我没有获得日志,那么您的代码就没有执行。t这是您的控制流/逻辑的问题,而不是UICollectionView的问题
[collectionView registerClass:forCellWithReuseIdentifier:]