Only now can I understand that uicollectionview is used in the same way as u I tableview.
If you are using a storyboard
In the production process, be sure to pay attention to the connection of datasource dalegate, and some custom connections between Dongdong and storyboard.
Drag a collectionview to the current viewcontroller and remove use autolayout. The collectionview contains a cell. The following is the custom cell Code. There are two methods: the first one.
You do not need to create a cell class, but you must mark the tag value of each control in your cell.
As follows:
-(NSInteger) numberOfSectionsInCollectionView :( UICollectionView *) collectionView
{
Return 1;
}
-(NSInteger) collectionView :( UICollectionView *) view numberOfItemsInSection :( NSInteger) section;
{
Return 6; // return 32 Images
}
// This function is very important. If you don't know how to use it, you can check the information!
-(UICollectionViewCell *) collectionView :( UICollectionView *) cv cellForItemAtIndexPath :( NSIndexPath *) indexPath;
{
UICollectionViewCell * cell = [cv dequeueReusableCellWithReuseIdentifier: @ "imgCell" forIndexPath: indexPath];
UILabel * titleLabel = (UILabel *) [cell viewWithTag: 11];
NSString * sttr = [[NSString alloc] initWithFormat: @ "Hello ~ % D ", indexPath. row];
[TitleLabel setText: sttr];
Return cell;
}
// Pass a value to the next view
-(Void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender
{
If ([[segue identifier] isEqualToString: @ "showDetail"])
{
}
}