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