I am trying to define my own implementation of UICollectionViewCell and use it in a UICollectionView . Here is what I did.
1- I use storyboards.
2- I added a UICollectionView to another view, it was a scene on a storyboard.
3- I pointed the datasource and delegate collections to the controller for the scene.
4- I presented implementations of the required methods in the controller.
5- I created a cell file .h and .m . In the .h file, I do
@interface HscCellView : UICollectionViewCell
6- I created a new view, so I got a new canvas, and in the corresponding section on the right, I indicated my class name (the same as in step 5), and provided a unique identifier.
7- In the controller for the scene, I defined the output in the .h file as a collection that I dragged.
@property (nonatomic, strong) IBOutlet UICollectionView *holesCollectionView;
and in viewDidLoad i do
[self.holesCollectionView registerClass:[HscCellView class] forCellWithReuseIdentifier:@"cellView"];
note that cellView is the unique identifier specified for my custom xib cell.
8- Finally, I implemented
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { HscCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellView" forIndexPath:indexPath]; return cell; }
When I run the application, I get a bunch of cellular views (9, since I specify 9 in the message numberOfItemsInSection ), but they are not my custom cell view. They have no size, color or label. I do not see any errors. I am stuck.
A few supporting questions.
When do I use the nib register and when do I register the class name? I saw how this was done in both directions, but it seems that you almost always finish both the code and the class definition code, is that true ?.
In step 6, when I specify a unique identifier in the canvas for the user view of the cells, does this mean that I do not need to register the class in viewDidLoad ?