Ios.uikit.12.uicollectionview

Source: Internet
Author: User

First, Case introduction: Display the picture in the collection form, 01

Figure 01

Second, the case steps:

1, choose Simple View aplication, named cq.38. Collection View, 02

Figure 02

2, main.storyboard,03

Figure 03

3, events.plist,04,05

4, CQ38ViewController.h

#import <UIKit/UIKit.h>@interface*events; @end

5, CQ38VIEWCONTROLLER.M

#import "CQ38ViewController.h"#import "CQ38CollectionViewCell.h"@interfaceCq38viewcontroller ()@end@implementationCq38viewcontroller- (void) viewdidload{[Super Viewdidload]; //additional setup after loading the view, typically from a nib.NSBundle*bundle =[NSBundle Mainbundle]; NSString*plistpath = [Bundle Pathforresource:@"Events"OfType:@"plist"]; //get all the data in a property list fileNsarray *array =[[Nsarray alloc] initwithcontentsoffile:plistpath]; Self.events=Array; }- (void) didreceivememorywarning{[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}-(BOOL) shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation{return(Interfaceorientation! =uiinterfaceorientationportraitupsidedown);}#pragmamark-uicollectionviewdatasource-(Nsinteger) Numberofsectionsincollectionview: (Uicollectionview *) collectionview{return[Self.events Count]/2;}-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) section{return 2;}-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{Cq38collectionviewcell*cell = [CollectionView dequeuereusablecellwithreuseidentifier:@"Cell"Forindexpath:indexpath]; Nsdictionary*Event= [self.events objectatindex: (indexpath.section*2+Indexpath.row)]; Cell.label.text= [EventObjectforkey:@"name"]; Cell.imageView.image= [UIImage imagenamed:[EventObjectforkey:@"Image"]]; returncell;}#pragmamark-uicollectionviewdelegate-(void) CollectionView: (Uicollectionview *) CollectionView Didselectitematindexpath: (Nsindexpath *) indexpath{nsdictionary*Event= [self.events objectatindex: (indexpath.section*2+Indexpath.row)]; NSLog (@"Select Event Name:%@", [EventObjectforkey:@"name"]); }@end

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.