IOS--Image Browser 2 (use Nsdictionary to store data)

Source: Internet
Author: User

Strong: Generic Object Weak:ui Control
#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 Mjviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
[Self changedata];
}
-(Nsarray *) imageData
{
if (_imagedata = = nil) {//Never initialized
Initializing data
Nsmutabledictionary *image1 = [Nsmutabledictionary dictionary];
Image1[iconkey] = @ "Biaoqingdi";
Image1[desckey] = @ "In front of him, other god horse expression is weak!" ";
Nsmutabledictionary *image2 = [Nsmutabledictionary dictionary];
Image2[iconkey] = @ "Wangba";
Image2[desckey] = @ "Brother Why choose Eighth";
Nsmutabledictionary *image3 = [Nsmutabledictionary dictionary];
Image3[iconkey] = @ "Bingli";
Image3[desckey] = @ "This is also cruel";
Nsmutabledictionary *image4 = [Nsmutabledictionary dictionary];
Image4[iconkey] = @ "Chiniupa";
Image4[desckey] = @ "Chiniupa";
Nsmutabledictionary *image5 = [Nsmutabledictionary dictionary];
Image5[iconkey] = @ "Danteng";
Image5[desckey] = @ "Pro, can you change your screen name?" Haha ";
Nsmutabledictionary *image6 = [Nsmutabledictionary dictionary];
Image6[iconkey] = @ "Chiniupa";
Image6[desckey] = @ "new data";
_imagedata = @[image1, Image2, Image3, Image4, Image5];
}
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];
2. 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++; 0
2. Display the corresponding content according to the index
[Self changedata];
}
@end

IOS--Image Browser 2 (use Nsdictionary to store data)

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.