Continuation: iOS Development Basics-Image Switching (1), to improve the code inside (1).
Add a new array property to the Viewcontroller class:
@property (nonatomic, strong) Nsarray *infoarray; // Store picture Information
It is initialized by the self.infoarray getter method (lazy loading), where the _infoarray in the code cannot be replaced with Self.infoarray :
1 //get method for Infoarray2-(Nsarray *) Infoarray {3NSLog (@"need to get an array of picture information");4 //instantiate only once5 if(_infoarray = =Nil) {6NSLog (@"instantiating an array");7Nsdictionary *dict0 = @{@"name":@"beauty0",@"desc":@"Beauty No. 1th"};8Nsdictionary *dict1 = @{@"name":@"beauty1",@"desc":@"Beauty No. 2nd"};9Nsdictionary *dict2 = @{@"name":@"Beauty2",@"desc":@"Beauty No. 3rd"};TenNsdictionary *dict3 = @{@"name":@"Beauty3",@"desc":@"Beauty No. 4th"}; OneNsdictionary *dict4 = @{@"name":@"Beauty4",@"desc":@"Beauty No. 5th"}; A_infoarray =@[dict0, Dict1, Dict2, Dict3, Dict4]; - } - return_infoarray; the}
Modify The Change method as follows:
1 //View content update and display2- (void) Change {3 //Initialize two tags and a picture4Self.imageIcon.image = [UIImage imagenamed:self.infoarray[self.i][@"name"]];5Self.lastLabel.text = self.infoarray[self.i][@"desc"];6[Self.firstlabel settext:[nsstring stringWithFormat:@"%D/5", self.i+1]];7 8self.leftButton.enabled = (self.i! =0);//when the 1th picture is displayed, the left Turn button fails9self.rightButton.enabled = (self.i! =4);//when the 5th picture is displayed, the right turn button failsTen}
Reference Blog: iOS Development UI chapter-Simple Browser Viewer
Example code: HTTP://PAN.BAIDU.COM/S/1XFJ10
iOS Development Basics-Image Switching (2)