//
VIEWCONTROLLER.M
19- Picture Browser
//
Created by Hongqiangli on 2017/7/31.
Copyright Li Hongqiang year . All rights reserved.
//
#define ICON @"icon"
#define DESC @"desc"
#import "ViewController.h"
@interface viewcontroller ()
/**
record the current index number
*/
@property(nonatomic,assign)int index;
/**
the previous one
*/
-(ibaction) previous;
/**
Next One
*/
-(ibaction) next;
/**
Description
*/
@property (weak, nonatomic) iboutlet UILabel *desclabel;
/**
Previous Button
*/
@property (weak, nonatomic) iboutlet UIButton *previousbtn;
/**
Next button
*/
@property (weak, nonatomic) iboutlet UIButton *nextbtn;
/**
Index label
*/
@property (weak, nonatomic) iboutlet UILabel *nolabel;
@property (weak, nonatomic) iboutlet uiimageview *mainimageview;
/**
General OC objects are modified with strong
*/
@property(nonatomic,strong)Nsarray *images;
@end
@implementation Viewcontroller
-(nsarray *) images{
if(_images = = Nil) {
// Dictionary mode initialization
nsmutabledictionary *dic1 = [nsmutabledictionary dictionary];
Dic1[icon] = @ "Biaoqingdi";
Dic1[desc] = @ " in front of him, other god horse expression is weak!" ";
nsmutabledictionary *dict2 = [nsmutabledictionary dictionary];
dict2[icon]= @ "Wangba";
Dict2[desc] = @ " brother why Choose Eighth ";
nsmutabledictionary *dict3 = [nsmutabledictionary dictionary];
dict3[icon]= @ "Bingli";
Dict3[desc] = @ " that's a cruel!" ";
nsmutabledictionary *dict4 = [nsmutabledictionary dictionary];
dict4[icon]= @ "Chiniupa";
Dict4[desc] = @ " This little girl eats a cow and kills the cows. "
nsmutabledictionary *dict5 = [nsmutabledictionary dictionary];
dict5[icon]= @ "Danteng";
Dict5[desc] = @ " Pro, can you change your screen name?" Haha ";
_images = @[dic1,dict2,dict3,dict4,dict5];
// load in a plist way
// get The full path to the plist file
nsstring *path = [[nsbundle mainbundle]pathforresource:@ "Images" OfType:@ "plist"];
_images = [nsarray arraywithcontentsoffile:p ath];
}
return _images;
}
-(void) viewdidload {
[Super viewdidload];
[self changdata];
}
/**
Click on the previous one
*/
-(ibaction) Previous {
_index--;
[self changdata];
}
/**
Next One
*/
-(ibaction) Next {
_index++;
[self changdata];
}
-(void) changdata{
_nolabel.text = [NSString stringWithFormat:@ "%d/%ld", _index + 1, _images.count];
Nsdictionary *dict = _images[_index];
NSString *iconstr = Dict[icon];
NSString *descstr = Dict[desc];
_mainimageview.image = [UIImage imagenamed:iconstr];
_desclabel.text = Descstr;
// judgment button can not click
_previousbtn.enabled = (_index! = 0);
_nextbtn.enabled = (_index! = 4);
}
@end
ios-Picture Browser (dictionary and plist file usage)