Use switch in OC for picture browsing

Source: Internet
Author: User

Image browsing, home and last page, need to disable the "Up and Down" button, the middle page and restore the button, feel switch more concise than if:

1-(void) Turnpage: (BOOL) isup{2     if(isUp) {3self.currentnum++;4}Else{5self.currentnum--;6     }7     Switch(self.currentnum) {8          Case 0:9             //"prev" InvalidTenself.lastButton.enabled =NO; One              Break; A          Case 1: -             //Open the defunct "previous page" -self.lastButton.enabled =YES; the              Break; -          Casequestion_num-2: -             //Open the defunct "next page" -self.nextButton.enabled =YES; +              Break; -          Casequestion_num-1: +             //"Next page" Expires Aself.nextButton.enabled =NO; at              Break;  -         default: -              Break; -     } -Self.currentdictionary =[Self.questionarray ObjectAtIndex:self.currentNum]; -     //Reset UI in [self setui]; -}

The basic syntax rule for supplemental switch is to first execute the case (the case criterion must be constant), break out of the switch snippet after execution, and traverse the case to execute default.

Case,default are interchangeable (should the high-frequency case be placed in front of the implementation efficiency?) Tried under almost no effect, 10 case loop 1000 times 200 microseconds)

Use switch in OC for picture browsing

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.