1 //2 3 //HYVIEWCONTROLLER.M4 5 //01-Image Browser Review6 7 //8 9 //Created by Apple on 15-4-10.Ten One //Copyright (c) 2015 Apple. All rights reserved. A - // - the - - #import "HYViewController.h" - + - + @interfaceHyviewcontroller () A at-(ibaction) last; - --(ibaction) next; - - /** Display the number of pictures*/ - in@property (Weak, nonatomic) Iboutlet UILabel *numlable; - to /** Show Pictures*/ + -@property (Weak, nonatomic) Iboutlet Uiimageview *MyImage; the * /** Display the description of the picture*/ $ Panax Notoginseng@property (Weak, nonatomic) Iboutlet UILabel *desclable; - the /** Show the status of the button*/ + A@property (Weak, nonatomic) Iboutlet UIButton *lastbtn; the +@property (Weak, nonatomic) Iboutlet UIButton *nextbtn; - $ $ - /** Collection of picture data*/ - the@property (nonatomic,strong) Nsarray *Arrayimage; - Wuyi /** Record the index of the picture display*/ the -@property (nonatomic,assign)intindex; Wu - @end About $ - - @implementationHyviewcontroller - A /** Lazy loading of data*/ + the-(Nsarray *) Arrayimage - $ { the the if(_arrayimage==Nil) the the { - in //First time loading the the //Initializing Data About the //1. Use Mainboundle to access any resource on the mobile resource bundle the theNSBundle *bdle=[NSBundle Mainbundle]; + - //2. Get the full path the BayiNSString *path= [Bdle pathforresource:@"Changedata"OfType:@"plist"]; the the //3. Read resources under the full path - -_arrayimage=[Nsarray Arraywithcontentsoffile:path]; the the } the the - the return_arrayimage; the the }94 the the the //This method is called when the controller's view initialization is complete98 About- (void) Viewdidload - 101 {102 103 [Super Viewdidload];104 the [self changedata];106 107 108 }109 the 111 the /** Changes in data*/113 the-(void) Changedata the the {117 118 //1. Change the serial number119 -Self.numlable.text=[nsstring stringWithFormat:@"%d/%d", self.index+1, Self.arrayimage.count];121 122 //2. Remove the array of values in the dictionary array name [index subscript]123 124Nsdictionary *dectimage=Self.arrayimage[self.index]; the 126 //3. Change the picture127 -Self.myimage.image=[uiimage imagenamed:dectimage[@"icon"]];129 the //4. Change the description131 theself.desclable.text=dectimage[@"desc"];133 134 //5. Change the state of the button135 136Self.lastbtn.enabled= (self.index!=0);137 138Self.nextbtn.enabled= (self.index!=self.arrayimage.count-1);139 $ }141 142 143 144 /** Show Previous picture*/145 146-(ibaction) last147 148 {149 Maxself.index--;151 the [self changedata];153 154 155 156 } 157 158 /** Show Next picture*/159 the-(ibaction) Next161 162 {163 164self.index++;165 166 [self changedata];167 168 }169 the @end171 172 173 174 //Personal Summary: Deferred load design, use of nsboundle, use of plist files
The implementation of the simple picture browser in the UI Foundation article-ios