Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ios中的一个控制器中注册多个UICollectionViewCell类_Ios_Objective C_Uicollectionview - Fatal编程技术网

如何在ios中的一个控制器中注册多个UICollectionViewCell类

如何在ios中的一个控制器中注册多个UICollectionViewCell类,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我正在使用两个不同的uicollectionview和两个不同的uicollectionviewcell,并且cell的结构也不同。如何在一个控制器视图中注册这两个cell类 [self.collectionView registerClass:[HCTabBarItemCell class] forCellWithReuseIdentifier:[HCTabBarItemCell reuseIdentifier]]; 如果从.xib文件加载自定义UIColle

我正在使用两个不同的uicollectionview和两个不同的uicollectionviewcell,并且cell的结构也不同。如何在一个控制器视图中注册这两个cell类

    [self.collectionView registerClass:[HCTabBarItemCell class]
            forCellWithReuseIdentifier:[HCTabBarItemCell reuseIdentifier]];
如果从.xib文件加载自定义UICollectionViewCell子类,还应注册其nib:

    [self.collectionView registerNib:[HCTabBarItemCell nibName] 
          forCellWithReuseIdentifier:[HCTabBarItemCell reuseIdentifier]];
在(基本)自定义单元类中声明和实现类方法nibName和reuseIdentifier的位置:

+ (NSString *)reuseIdentifier {
    return NSStringFromClass([self class]);
}

+ (UINib *)nibName {
    return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
}
然后通过reuseIdentifier在cellForRow方法中获取自定义单元格:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
                   cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HCTabBarItemCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:[HCTabBarItemCell reuseIdentifier]
                                                                            forIndexPath:indexPath];
    return cell;
}

我在一个控制器视图中使用两个不同的uicollectionview和两个不同的uicollectionview单元格,单元格的结构也不同如何在一个控制器视图中注册两个单元格类我正在创建类标识符nib和register,但只有一个集合视图工作,第二个视图没有任何单元格。您可以用一个单元格注册nib标识符,然后向另一个注册类,尝试使用如下内容使它们具有相同的标识符:NSStringFromClass([TitleCollectionViewCel class])在cellForRow委托方法中,您应该使用在registerClass:method中声明的重用标识符。您能根据我的代码填充给出完整的代码吗,我这样做,但它不能正常工作,一次只能初始化一个collectionview。你看我的代码如果有可能给我完整的代码,这对我很有帮助。谢谢。Homeview.xib中有两个集合视图,它为每个集合视图导入两个collectionviewcell类,我希望在一个类(Homeview.xib)中同时使用这两个集合视图,请给我完整的代码以帮助我。