IOS--Image Browser 3 (store data in a plist file)

Source: Internet
Author: User

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)

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.