Photo DEMO

尚有一个 BUG,真机无法加载图片,模拟器可以。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// ViewController.m
// Photo DEMO
//
// Created by Will on 5/24/15.
// Copyright (c) 2015 gewill.org. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (nonatomic, assign) int index;
@property (nonatomic, strong) NSArray *imageDicts;

@end

@implementation ViewController

- (NSArray *)imageDicts{
if (!_imageDicts) {
_imageDicts = [NSArray arrayWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"imageDate.plist" ofType:nil]];
}
return _imageDicts;
}

- (IBAction)clickLeftBtn:(UIButton *)sender {
self.index --;
[self clickBtn];
}
- (IBAction)clickRightBtn:(UIButton *)sender {
self.index ++;
[self clickBtn];
}

- (void)clickBtn{
self.topLabel.text = [NSString stringWithFormat:@"%d/%d", self.index+1, self.imageDicts.count];
self.descLabel.text = self.imageDicts[self.index][@"description"];
self.imageView.image = [UIImage imageNamed:self.imageDicts[self.index][@"name"]];

self.leftBtn.enabled = (self.index != 0);
self.rightBtn.enabled = (self.index != 4);

}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end