0

All,

I am adding a UICollectionView to a UIView but it's failing to load cells because it seems that this:

[self.buttonsCollectionView registerNib:[UINib nibWithNibName:@"AccountMenuCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"AccountMenuCell"];

Is getting loaded after it hits the delegates for the UICollectionView. Normally this would be placed in viewDidLoad but is not available in a UIView.

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

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

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

     return cell;

 }

Any guidance?

EDIT:

So I am using a view from the storyboard initially and then adding a subview which is Account Menu. Within this view I have a Collection View.

n00bProgrammer
  • 4,151
  • 3
  • 29
  • 59
Adam Rush
  • 91
  • 8
  • take this link http://stackoverflow.com/questions/14466959/create-uicollectionviewcell-subclass-with-xib else use http://stackoverflow.com/questions/17856055/creating-a-uicollectionview-programmatically and finally try this http://adoptioncurve.net/archives/2012/09/a-simple-uicollectionview-tutorial/ – Anbu.Karthik Jan 14 '15 at 11:07
  • Don't post code in a comment. When people ask for more details, go back and edit your question to make it clearer. This is especially important with code, since code is all but unreadable in the form it's displayed in a comment. – Duncan C Jan 14 '15 at 12:00
  • You need to add a lot more background information (to your original question). Are you using storyboards or XIB files to create this view? (view controller?) Or are you creating it with code? Explain the life cycle of your collection view in detail. – Duncan C Jan 14 '15 at 12:01
  • Yeah I read those Anbu, the problem is - it's hitting the collection view delegates before loading the registerNib line. As normally this would sit in viewDidLoad but I am in a UIView with this not available. – Adam Rush Jan 14 '15 at 12:12

1 Answers1

0

Try to use with the default method and instantiate your Cell inside of the cellForItem...

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

and .. verify with Breakpoints if your code is running..