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