黄智勇 发表于 2015-12-31 16:04:17

Target/Action(Chapter 5 of Cocoa Programming for Mac OS X)

AppController.h

1 #import <Foundation/Foundation.h>
2
3
4 @interface AppController : NSObject
5 {
6   IBOutlet NSTextField *textField;
7   NSSpeechSynthesizer *speechSynth;
8 }
9
10 - (IBAction)sayIt:(id)sender;
11 - (IBAction)stopIt:(id)sender;
12
13 @end  



1 #import "AppController.h"
2
3
4 @implementation AppController
5
6 - (id)init
7 {
8   ;
9   
10   NSLog(@"init");
11   
12   speechSynth = [ initWithVoice:nil];
13   return self;
14 }
15
16 - (IBAction)sayIt:(id)sender
17 {
18   NSString *string = ;
19   if( == 0)
20   {
21         NSLog(@"string from %@ is of zero-length", textField);
22         return;
23   }
24   
25   ;
26   NSLog(@"Have started to say: %@", string);
27 }
28
29 - (IBAction)stopIt:(id)sender
30 {
31   NSLog(@"stopping");
32   ;
33 }
34
35 @end  
  
页: [1]
查看完整版本: Target/Action(Chapter 5 of Cocoa Programming for Mac OS X)