IOS: Build and use of UICollectionView
The first part is about the three protocol methods.
The usage of the first two is similar to that of tableView, and the third is the protocol of the end view of the header view. (For the end view of the header view, write proxy and write registration are required. If the header view is missing, it will not work .) After registration, you do not need to manage reuse issues. This is simple. This can be very easy to use. A lot of things can be solved. Otherwise, three tableviews need to slide together and observe each other. Once the change changes, it is very unscientific to use the ContentOffset of scroller to control the slide, in this case, the three will slide together.
In the second part, you must first create a layout, UICollectionViewFlowLayout
// Create the layout object UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init]; // set the cell size flowLayout. itemSize = CGSizeMake (80, 80); // sets the height of the header view flowLayout. headerReferenceSize = CGSizeMake (0, 30); // The flowlaout attribute that slides horizontally. scrollDirection = uicollectionviewscrolldirehorhorizontal; // It will be initialized when you create a collectionView, which is very convenient (you can directly bring the layout) _ myCollectionView = [[UICollectionView alloc] initWithFrame: C GRectMake (0,200,320,280) collectionViewLayout: flowLayout]; _ myCollectionView. tag = 200; _ myCollectionView. backgroundColor = [UIColor greenColor]; _ myCollectionView. delegate = self; _ myCollectionView. dataSource = self; // Add it to the home page [self. view addSubview: _ myCollectionView]; // register a collectionCell [_ myCollectionView registerClass: [UICollectionViewCell class] forCellWithReuseIdentifier: @ "myheheIdentifier"]; // The registration of the collection header view is wonderful. The header view must also be registered with [_ myCollectionView registerClass: [UICollectionReusableView class] forSupplementaryViewOfKind: appswithreuseidentifier: @ "Identifierhead"]; # pragma mark-UICollectionViewDataSource // specify the number of groups, a large group !! Not a row, it is a big group composed of N rows (differentiated from the following)-(NSInteger) numberOfSectionsInCollectionView :( UICollectionView *) collectionView {return 2;} // specifies the number of cells, this is the number of cells in a group. e. g: A cell is an image (NSInteger) collectionView :( UICollectionView *) collectionView numberOfItemsInSection :( NSInteger) section {return 10;} // construct a cell-(UICollectionViewCell *) collectionView :( UICollectionView *) collectionView cellForItemAtIndexPath :( NSIndexPath *) indexPath {if (collectionView. tag = 200) {UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier: @ "myheheIdentifier" forIndexPath: indexPath]; cell. backgroundColor = [UIColor purpleColor]; return cell;} // creates a group's header view (UICollectionReusableView *) collectionView :( UICollectionView *) collectionView viewForSupplementaryElementOfKind :( NSString *) kind atIndexPath :( NSIndexPath *) indexPath {UICollectionReusableView * headView = [collectionView failed: kind withReuseIdentifier: @ "Identifierhead" forIndexPath: indexPath]; headView. backgroundColor = [UIColor blueColor]; return headView;} // set the cell size using the Protocol-(CGSize) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout layout :( NSIndexPath *) indexPath {CGFloat rd = arc4random () % 90; return CGSizeMake (90, rd );}