花蜻宽 发表于 2015-12-31 10:59:18

NSTimer(Chapter 24 of Cocoa Programming for Mac OS X)

1 #import "AppController.h"
2 #import "BigLetterView.h"
3
4 #define MAX_COUNT (100)
5 #define COUNT_STEP (5)
6
7 @implementation AppController
8
9 - (id)init
10 {
11   ;
12   
13   letters = [ initWithObjects:@"a", @"s", @"d", @"f", @"j", @"k", @"l", @";", nil];
14   srandom(time(NULL));
15   return self;
16 }
17
18 - (void)awakeFromNib
19 {
20   ;
21 }
22   
23 - (void)resetCount
24 {
25   ;
26   count = 0;
27   ;
28 }
29
30 - (void)incrementCount
31 {
32   ;
33   count = count + COUNT_STEP;
34   if (count > MAX_COUNT)
35   {
36         count = MAX_COUNT;
37   }
38   ;
39 }
40
41 - (void)showAnotherLetter
42 {
43   int x = lastIndex;
44   while (x == lastIndex)
45   {
46         x = random() % ;
47   }
48   lastIndex = x;
49   ];
50   
51   ;
52 }
53
54 - (IBAction)stopGo:(id)sender
55 {
56   if (timer == nil)
57   {
58         NSLog(@"Starting");
59         
60         timer = [ retain];
61   }
62   else
63   {
64         NSLog(@"Stopping");
65         ;
66         ;
67         timer = nil;
68   }
69 }
70
71 - (void)checkThem:(NSTimer *)aTimer
72 {
73   if([ isEqual:])
74   {
75         ;
76   }
77   if (count == MAX_COUNT)
78   {
79         NSBeep();
80         ;
81   }
82   else
83   {
84         ;
85   }
86
87 }
88
89 @end
页: [1]
查看完整版本: NSTimer(Chapter 24 of Cocoa Programming for Mac OS X)