Storing data in a plist file
#define Iconkey @ "icon"
#define DESCKEY @ "desc"
#import "ViewController.h"
@interface Viewcontroller ()
-(ibaction) previous;
-(ibaction) next;
@property (Weak, nonatomic) Iboutlet UIButton *previousbtn;
@property (Weak, nonatomic) Iboutlet UIButton *nextbtn;
@property (Weak, nonatomic) Iboutlet UILabel *nolabel;
@property (Weak, nonatomic) Iboutlet Uiimageview *iconview;
@property (Weak, nonatomic) Iboutlet UILabel *desclabel;
The record is currently showing the first few pictures
@property (nonatomic, assign) int index;
Picture data collection
@property (nonatomic, strong) Nsarray *imagedata;
@end
@implementation Viewcontroller
-(void) viewdidload
{
[Super Viewdidload];
The default is to display the data corresponding to index 0
[Self changedata];
}
-(Nsarray *) imageData
{
if (_imagedata = = nil) {//Never initialized
Initializing data
File: Full path
NSBundle: A nsbundle represents a folder
Use Mainbundle to access any resource in the software resource bundle
NSBundle *bundle = [NSBundle mainbundle];
Get the full path of imagedata.plist
NSString *path = [Bundle pathforresource:@ "ImageData" oftype:@ "plist"];
_imagedata = [Nsarray Arraywithcontentsoffile:path];
}
return _imagedata;
}
#pragma mark changes the data
-(void) Changedata
{
1. Change the data
Self.noLabel.text = [NSString stringwithformat:@ "%d/%d", Self.index + 1, Self.imageData.count];
2. Remove the dictionary data for index
Nsdictionary *imagedict = Self.imagedata[self.index];
3. Setting up a picture
Self.iconView.image = [UIImage Imagenamed:imagedict[iconkey]];
4. Settings description
Self.descLabel.text = Imagedict[desckey];
5. Change the button state
self.previousBtn.enabled = (Self.index! = 0);
self.nextBtn.enabled = (Self.index! = self.imagedata.count-1);
}
#pragma mark, the last one.
-(ibaction) Previous {
1. Reducing the Index
self.index--;
2. Change the data
[Self changedata];
}
#pragma Mark's next one.
-(ibaction) Next {
1. Add index
self.index++;
2. Display the corresponding content according to the index
[Self changedata];
}
@end
IOS--Image Browser 3 (store data in a plist file)