iOS Development Basics-Image Switching (2)

Source: Internet
Author: User

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)

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.