iOS Development-Schulte table

Source: Internet
Author: User
Tags set background

Weekend idle to see a concept, very interesting, Schulte table, online there are many people have written similar demo, I idle to write a bit, Schulte table sounds very tall on the look, but my understanding is a square matrix in a variety of small lattice, can be letters, numbers or words, The Schulte watch can exercise visual nerve endings through dynamic exercises. Psychology uses this table to study and develop the speed of psychological perception, which includes the speed of the visual directed search movement. Cultivate concentration, distribution, control ability, expand the view, speed up the video, improve the visual stability, discernment, directional search ability. The longer you practice, the less time you'll need to see the table. With the deepening of the practice, the eye's peripheral visual ability improves, not only the beginner can effectively expand the view, speed up the reading rhythm, exercise the eyes quickly read, and for entering the improvement phase, at the same time expand the aspect of the view, to reach Yimushihang, one eye page is very effective. Each table in alphabetical order, quickly find all the characters, an average of 1 characters with 1 seconds of good results, that is 9 lattice with 9 seconds, 16 grid with 16 seconds, 25 grid with 25 seconds. (Baidu Encyclopedia)

Page Layout

According to the above concept, the approximate page layout is 3*3 nine Gongge, generally choose the number of exercises, there is no special more to get, the layout of the Main.storyboard is as follows:

All buttons need to be made into a collection, and all buttons share an event:

Collection Demo:

Button Sharing Event Demo:

Demo Implementation

The interface above is mainly the number 1, so the need for a method to generate a random array, as follows, to generate a random array of non-repeating the approximate rule is to first the top of an array, after that, the array will need to be scrambled, random numbers randomly generated index:

-(Nsarray *) getdataarray{    //Arrays Nsmutablearray *arr=[nsmutablearray Array] required to be displayed    ;    for (Nsinteger i=1; i<10; i++) {        [arr addobject:@ (i)];    }    Nsinteger Count=[arr Count];    Generate a random array for    (Nsinteger i=0; i<count; i++) {        nsinteger index=arc4random ()% (count-i) +i;        [arr Exchangeobjectatindex:index withobjectatindex:i];    }    return arr;}

Assign the values in the array to the buttons of the page:

-(void) initbuttontitle{    //instantiating a mutable array of result sets    Self.resultarr=[nsmutablearray array];    Nsarray *arr=[self Getdataarray];    For (UIButton *button in self.visionbuttons) {        nsstring *result=[arr[button.tag-1]stringvalue];        [Button Settitle:result Forstate:uicontrolstatenormal];        Reset the button's background and status        [button Setbackgroundcolor:[uicolor Yellowcolor]        when you start over. [Button Setenabled:yes];    }    [_timerlabel settext:@ "00:00"];    Self.timer=[nstimer scheduledtimerwithtimeinterval:0.1 invocation:nil Repeats:yes];}

The corresponding program is called when the Viewdidload is started:

  [Self initbuttontitle];

This time the layout of the page should look like this:

To do this basically the program is almost finished, and then the timing, after the completion of statistics, idle to see the specific effect, and then look at the code may be a little better:

function is basically set the background color of the button, whether you can click, timing, zeroing, bullets, display the results of the previous click, step by Step analysis:

Define member variables timing and store results:

@interface Viewcontroller () @property nsmutablearray *resultarr; @property nstimer *timer; @property nsdate  * Begindate; @end

To set the timer:

   Self.timer=[nstimer scheduledtimerwithtimeinterval:0.1 Invocation:nil Repeats:yes];

Set the background color and display of the button:

[Button Setbackgroundcolor:[uicolor Yellowcolor];        [Button Setenabled:yes];

Statistics Time:

Nsinteger alltime=[_timer.firedate timeintervalsincedate:_begindate];    NSString *timeformat=[nsstring stringwithformat:@ "%02ld:%02ld", alltime/1000,alltime%1000];    [_timerlabel Settext:timeformat];

Judging the result, if all the results are ascending then it is successful, otherwise it is a failure:

Determine if an array is ascending-(BOOL) GETARRAYASC: (Nsarray *) originalarr{for    (Nsinteger i=0; I<[originalarr count]-1; i++) {        if (originalarr[i]>originalarr[i+1]) {            return NO;        }    }    return  YES;}

Click events for all buttons as follows:

-(Ibaction) GetResult: (ID) Sender {UIButton *button= (UIButton *) sender;    Set background color [button Setbackgroundcolor:[uicolor Greencolor]];    Click on the button once to no longer click [Button Setenabled:no];    Nsinteger Value=[[[button Titlelabel] [text] integervalue];    [Self.resultarr Addobject:[nsnumber Numberwithinteger:value];        After clicking the first button, set the start time if ([Self.resultarr count]==1) {//Game start time _begindate=[nsdate Date];    Game start [_timer fire];    } Nsinteger alltime=[_timer.firedate timeintervalsincedate:_begindate];    NSString *timeformat=[nsstring stringwithformat:@ "%02ld:%02ld", alltime/1000,alltime%1000];    [_timerlabel Settext:timeformat];        All clicks are completed after the call if ([Self.resultarr count]==9) {//Destroy timer [_timer invalidate];        Frame NSString *tip;        if ([self getArrayAsc:self.resultArr]) {[email protected] "Congratulations, through the game";        }else{[email protected] "Sorry, the game failed"; }//The results of the click are stitched with commas nsstring *resUltstr=[nsstring stringwithformat:@ "%@", [Self.resultarr componentsjoinedbystring:@ ","]]; Uialertview *alterview=[[uialertview alloc] initwithtitle:tip message:resultstr delegate:nil cancelButtonTitle:@ "OK"        Otherbuttontitles:nil];    [Alterview show]; }}

Code in VIEWCONTROLLER.M:

viewcontroller.m//tablevision////Created by Keso on 15/1/18.//Copyright (c) 2015 Keso. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @property Nsmutablearray *resultarr;@ Property Nstimer *timer; @property nsdate *begindate; @end @implementation viewcontroller-(void) viewdidload {[Super Vie    Wdidload];    Additional setup after loading the view, typically from a nib.    [Self initbuttontitle]; Self.timer=[nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:nil userInfo:nil Repeats:YES];} -(void) Triggertime: (Nstimer *) sender{}-(void) initbuttontitle{//instantiating a mutable array of result sets Self.resultarr=[nsmutablearray arr    AY];    Nsarray *arr=[self Getdataarray];        For (UIButton *button in self.visionbuttons) {nsstring *result=[arr[button.tag-1]stringvalue];        [Button Settitle:result Forstate:uicontrolstatenormal];        Reset the button's background and Status [button Setbackgroundcolor:[uicolor Yellowcolor] When you start over. [Button Setenabled:yes];    } [_timerlabel settext:@ "00:00"]; Self.timer=[nstimer scheduledtimerwithtimeinterval:0.1 invocation:nil Repeats:yes];} -(Ibaction) Onemore: (ID) Sender {[self initbuttontitle];}    -(Nsarray *) getdataarray{//Arrays Nsmutablearray *arr=[nsmutablearray Array] required to be displayed;    for (Nsinteger i=1; i<10; i++) {[Arr addobject:@ (i)];    } Nsinteger Count=[arr Count];        Generate a random array for (Nsinteger i=0; i<count; i++) {nsinteger index=arc4random ()% (count-i) +i;    [arr Exchangeobjectatindex:index withobjectatindex:i]; } return arr;}    -(Ibaction) GetResult: (ID) Sender {UIButton *button= (UIButton *) sender;    Set background color [button Setbackgroundcolor:[uicolor Greencolor]];    Click on the button once to no longer click [Button Setenabled:no];    Nsinteger Value=[[[button Titlelabel] [text] integervalue];    [Self.resultarr Addobject:[nsnumber Numberwithinteger:value]; After clicking the first button, set the start time if ([Self.resultarr count]==1) {//Game start time _begindate=[nsdate Date];       Game start [_timer fire];    } Nsinteger alltime=[_timer.firedate timeintervalsincedate:_begindate];    NSString *timeformat=[nsstring stringwithformat:@ "%02ld:%02ld", alltime/1000,alltime%1000];    [_timerlabel Settext:timeformat];        All clicks are completed after the call if ([Self.resultarr count]==9) {//Destroy timer [_timer invalidate];        Frame NSString *tip;        if ([self getArrayAsc:self.resultArr]) {[email protected] "Congratulations, through the game";        }else{[email protected] "Sorry, the game failed"; }//The results of the click are stitched with commas nsstring *resultstr=[nsstring stringwithformat:@ "%@", [Self.resultarr Componentsjoinedbyst                Ring:@ ","]]; Uialertview *alterview=[[uialertview alloc] initwithtitle:tip message:resultstr delegate:nil cancelButtonTitle:@ "OK"        Otherbuttontitles:nil];    [Alterview show];    }}-(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} Determine if an array is ascending-(BOOL) GETARRAYASC: (Nsarray *) originalarr{for (Nsinteger i=0; I<[originalarr count]-1; i++) {if (Originalarr[i]        >originalarr[i+1]) {return NO; }} return YES; @end

iOS Development-Schulte table

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.