Code Optimization---Main method as concise as possible

Source: Internet
Author: User

eg. super Guess < Next button operation optimization >

Total Effect:

1 #pragmaMark's next question.2-(ibaction) nextquestion3 {4     //1. Index of current answer5self.index++;6     //2. Remove the problem model data from the array by index7Hmquestion *question =Self.questions[self.index];8     9     //3. Setting up basic informationTen [self setupbasicinfo:question]; One         //4. Set Answer button A     //Remove all buttons from the answer area first - [self creatanswerbuttons:question]; -     //5. Set the option button the [self createoptionbuttons:question]; - } -  -  + /** Set BASIC information*/ --(void) Setupbasicinfo: (Hmquestion *) Question + { ASelf.noLabel.text = [NSString stringWithFormat:@"%d/%d", Self.index +1, Self.questions.count]; at      -Self.titleLable.text =Question.title; - [Self.iconbutton setimage:[uiimage ImageNamed:question.icon] forstate:uicontrolstatenormal]; -     //If you reach the next question, disable the next day cow -self.nextQuestionButton.enabled = (Self.index <self.questions.count-1); -      in  -  to } +  - /** Create an Answer area button*/ the  *-(void) Creatanswerbuttons: (Hmquestion *) Question $ {Panax Notoginseng      for(UIView *btninchSelf.answerView.subviews) {//UIButton *btn in Self.answerView.subviews all UI controls inherit from UIView - [btn Removefromsuperview]; the          +     } ACGFloat answerw =Self.answerView.bounds.size.width; the     intLenght =question.answer.length; +CGFloat Answerx = (answerw-kbuttonwidth *lenght-kbuttonmargin * (Lenght-1))*0.5; -     //Create all answer buttons $      for(inti =0; I < lenght; i++) { $CGFloat x = Answerx +i* (kbuttonmargin +kbuttonwidth); -UIButton *btn = [[UIButton alloc] Initwithframe:cgrectmake (x,0, Kbuttonwidth, Kbuttonheight)]; -         //btn.backgroundcolor =[uicolor Whitecolor]; the[Btn setbackgroundimage:[uiimage imagenamed:@"Btn_answer"] forstate:uicontrolstatenormal]; -[Btn setbackgroundimage:[uiimage imagenamed:@"btn_answer_highlighted"]forstate:uicontrolstatehighlighted];Wuyi          the [Self.answerview addsubview:btn]; -     } Wu      -  About  $  - } -  - /** Selected Button*/ A-(void) Createoptionbuttons: (Hmquestion *) Question + { the      for(UIView *viewinchself.optionsView.subviews) { - [view Removefromsuperview]; $     } theCGFloat optionw =Self.optionsView.bounds.size.width; theCGFloat Optionx = (Optionw-ktotolcol * kbuttonwidth-(Ktotolcol-1) *kbuttonmargin) *0.5; the      for(inti =0; I <question.options.count; i++) { the         intRow =i/ktotolcol;//Line -         intcol = I%ktotolcol;//column inCGFloat x = Optionx +col * (Kbuttonmargin +kbuttonwidth); theCGFloat y = row * (Kbuttonmargin +kbuttonheight); theUIButton *btn =[[UIButton alloc]initwithframe:cgrectmake (x, Y, Kbuttonwidth, kbuttonheight)]; About          the          the         //btn.backgroundcolor =[uicolor Whitecolor]; the[Btn setbackgroundimage:[uiimage imagenamed:@"btn_option"] forstate:uicontrolstatenormal]; +[Btn setbackgroundimage:[uiimage imagenamed:@"btn_option_highlighted"] forstate:uicontrolstatehighlighted]; -         //Set Alternate answers the [btn Settitle:question.options[i] forstate:uicontrolstatenormal];Bayi [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; the          the [Self.optionsview addsubview:btn]; -          -     } the  the}

Code Optimization---Main method as concise as possible

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.