IOS -- UICollectionView (rolling view) entry, uicollectionview Rolling

Source: Internet
Author: User

IOS -- UICollectionView (rolling view) entry, uicollectionview Rolling

UICollectionView

@ Interface UICollectionView: The UIScrollView UICollectionView and UICollectionViewController classes are newly introduced iOS6 APIs for displaying the set view. The layout is more flexible and supports multi-column layout. The usage is similar to the UITableView and UITableViewController classes. To use UICollectionView, you must implement the following protocols: UICollectionViewDataSource, UICollectionViewDelegate, and UICollectionViewDelegateFlowLayout. Initialization: // initialize the layout class (a subclass of UICollectionViewLayout) UICollectionViewFlowLayout * fl = [[UICollectionViewFlowLayout alloc] init]; // initialize collectionViewself. collectionView = [[UICollectionView alloc] initWithFrame: CGRectZero collectionViewLayout: fl]; // sets proxy self. collectionView. delegate = self; self. collectionView. dataSource = self; -------------------- protocol to be implemented: UICollectionViewDataSource, UICollectionViewDelegateFlowLayo UtPS: Listener is a sub-Protocol of UICollectionViewDelegate ---------------- register the corresponding UICollectionViewCell subclass to collectionView for extracting and displaying from the queue-(void) registerClass :( Class) cellClass identifier :( NSString *) identifier; PS: if it is created using nib, use the following function for registration. -(Void) registerNib :( UINib *) nib forCellWithReuseIdentifier :( NSString *) identifier; to display the headerView or footerView of each section, you also need to register the corresponding subclass of UICollectionReusableView to collectionViewelementKind as the header or footer identifier. There are only two types of settings: response and response-(void) registerClass :( Class) viewClass forSupplementaryViewOfKind :( NSString *) elementKind withReuseIdentifier :( NSStrin G *) identifier; PS: if it is created using nib, use the following function for registration. -(Void) registerNib :( UINib *) nib identifier :( NSString *) kind withReuseIdentifier :( NSString *) identifier; ------------------ implement protocol functions: similar to DataSource and Delegate of UITableView, big data can be understood by yourself. DataSource: // number of cells in each group-(NSInteger) collectionView :( UICollectionView *) collectionView numberOfItemsInSection :( NSInteger) section; // defines and returns each cell-(UICollectionViewCell *) collectionView :( UICollectionView *) collectionView cellForItemAtIndexPath :( NSIndexPath *) indexPath; // number of groups in collectionView-(NSInteger) numberOfSectionsInCollectionView :( UICollectionView *) collectionView; // define and return each headerView or footerV Iew-(UICollectionReusableView *) collectionView :( UICollectionView *) collectionView viewForSupplementaryElementOfKind :( NSString *) kind atIndexPath :( NSIndexPath *) indexPath; the preceding method must be used, if the layout does not set the size for headerView or footerView (the default size is CGSizeZero), this method will not be called. Therefore, if you need to display the header or footer, You need to manually set the size. You can set the headerReferenceSize and footerReferenceSize attributes of UICollectionViewFlowLayout to globally control the size. Alternatively, you can set-(CGSize) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout layout :( NSInteger) section;-(CGSize) collectionView :( UICollectionView *) by reloading the following proxy methods *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout layout :( NSInteger) section; Delegate: // the size of each cell-(CGSize) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout border :( NSIndexPath *) indexPath; // you can set the cell boundary of each group. For details, see-(UIEdgeInsets) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout) section;

 

// Cell minimum row spacing-(CGFloat) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout layout :( NSInteger) section; // cell minimum column spacing-(CGFloat) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout minimumInteritemSpacingForSectionAtIndex :( NSInteger) section; // called when cell is selected-(void) collectionView :( uicollectionctionview *) collectionView didSelectItemAtIndexPath :( NSIndexPath *) indexPath; // called when the cell is deselected (takes effect only when multiple selections are selected)-(void) collectionView :( UICollectionView *) collectionView paths :( NSIndexPath *) indexPath;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.