Ios uicollectionview (1)

Source: Internet
Author: User

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"])
{


}
}


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.