1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 5@property (Retain, nonatomic) Nsarray *pic;6 @property (Assign, nonatomic) Nsinteger index;7@property (Weak, nonatomic) Iboutlet UILabel *Lblindex;8@property (Weak, nonatomic) Iboutlet UILabel *Lbltitle;9@property (Weak, nonatomic) Iboutlet Uiimageview *Picture ;Ten-(Ibaction) Nextpicture: (ID) sender; One@property (Weak, nonatomic) Iboutlet UIButton *Btnnext; A --(Ibaction) Lastpicture: (ID) sender; -@property (Weak, nonatomic) Iboutlet UIButton *Btnlast; the - @end - @implementationViewcontroller - + -- (void) Viewdidload { + [Super Viewdidload]; A //let the first picture show up, so call it one at a time at [self nextpicture:nil]; - } - -- (void) didreceivememorywarning { - [Super didreceivememorywarning]; - } in - //Override Pic Property Get method---lazy load data to-(Nsarray *) pic +{/* - write code to load the data in the Picture.plist file to _pic; the 1. Get the path to the Picture.plist file * Ps:[nsbundle Mainbundle] Get the root directory of this app when it's installed on your phone $ then search the root directory for the picture.plist file pathPanax Notoginseng */ - if(_pic = =Nil) { theNSString *string= [[NSBundle mainbundle] Pathforresource:@" Picture"OfType:@". plist"]; +Nsarray *array = [Nsarray arraywithcontentsoffile:string]; A //NSLog (@ "%@", array); the +_pic =Array; - $ } $ return_pic; - } - the-(Ibaction) Nextpicture: (ID) Sender { - //1. Make the index self-addingWuyi_index++; the //2. Get the current image data from the array -Nsdictionary *dict = self.pic[self.index-1]; Wu //3. Set the acquired data to the controls on the interface -Self.lblIndex.text = [NSString stringWithFormat:@"%ld/%ld", Self.index,self.pic.count]; About //4. Use the Image property to set the picture inside the picture frame $Self.picture.image =[uiimage imagenamed:dict[@" Picture"]]; - -Self.lblTitle.text = dict[@"title"]; - //sets whether the Next button can be clicked Aself.btnnext.enabled = (_index! =self.pic.count); + //sets whether the "previous" button can be clicked theself.btnLast.enabled = (_index-1!=0); - $ } the the-(Ibaction) Lastpicture: (ID) Sender { the_index--; theNsdictionary *dict = self.pic[self.index-1]; -Self.lblIndex.text = [NSString stringWithFormat:@"%ld/%ld", Self.index,self.pic.count]; inSelf.picture.image =[uiimage imagenamed:dict[@" Picture"]]; theSelf.lblTitle.text = dict[@"title"]; the Aboutself.btnLast.enabled = (_index-1!=0); theself.btnnext.enabled = (_index! =self.pic.count); the } the @end
Development ideas:
1. Complete the basic function
2. Consider performance
(1) (Initialize operation, can call change directly)
(2) because you want to control the number and picture two variables, so consider using a dictionary instead of switch
(3) Each click, the dictionary needs to be created once, the efficiency of the underground, you can consider the creation of this part of the initialization method to go, so that only need to create once on the OK.
(4) Consider the drawbacks (the order of the code is very strict)
(5) Lazy loading (load only when needed, then when it is needed, and when the Get method is called)
(6) Come here every time? Inefficient-"Only the first call to the Get method is empty, when the array is instantiated and created, and other times the member variables are returned directly (only once)
Note the point:
1. The Call stack (order) of the method.
2. Use plist: Let the data operation more flexible, the data to go outside, decoupling, so that coupling is not too strong. is actually an XML, which is a special format of XML defined by Apple.
3.bundle-package (Read only)
Ios-ui-A Simple browser viewer program