Ios 将UICollectionView添加到UIView

Ios 将UICollectionView添加到UIView,ios,objective-c,uiview,uicollectionview,Ios,Objective C,Uiview,Uicollectionview,全部, 我正在将UICollectionView添加到UIView,但它无法加载传感器,因为它似乎: [self.buttonsCollectionView registerNib:[UINib nibWithNibName:@"AccountMenuCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"AccountMenuCell"]; 在命中UICollectionView的代理后正在加载。通常,这将被放置在viewDi

全部,

我正在将UICollectionView添加到UIView,但它无法加载传感器,因为它似乎:

[self.buttonsCollectionView registerNib:[UINib nibWithNibName:@"AccountMenuCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"AccountMenuCell"];
在命中UICollectionView的代理后正在加载。通常,这将被放置在viewDidLoad中,但在UIView中不可用

- (AccountMenuCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

     AccountMenuCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AccountMenuCell" forIndexPath:indexPath]; 

    [cell.accountMenuButton setTitle:@"Deposit" forState:UIControlStateNormal];

     return cell;

 }
有什么指导吗

编辑:


因此,我首先使用故事板中的一个视图,然后添加一个子视图,即Account菜单。在此视图中,我有一个集合视图。

尝试使用默认方法,并在cellForItem中实例化您的单元格

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
AccountMenuCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AccountMenuCell" forIndexPath:indexPath];
[cell.accountMenuButton setTitle:@"Deposit" forState:UIControlStateNormal];
return cell;
}

和。。如果代码正在运行,请使用断点进行验证

获取此链接,然后使用,最后尝试在注释中使用此“请勿发布代码”。当人们询问更多细节时,请返回并编辑您的问题以使其更清楚。这对于代码尤其重要,因为代码在注释中显示的形式几乎不可读。您需要(在原始问题中)添加更多的背景信息。您是否使用故事板或XIB文件创建此视图?(视图控制器?)?详细解释集合视图的生命周期。是的,我读过这些Anbu,问题是-它在加载registerNib行之前影响了集合视图委托。正常情况下,这会出现在viewDidLoad中,但我在UIView中,此选项不可用。尝试此选项后,它在命中此代码之前崩溃。