Target/Action(Chapter 5 of Cocoa Programming for Mac OS X)
2019-08-01 21:22
405 查看
原文链接:https://www.geek-share.com/detail/2505795080.html
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
2
3
4 @implementation AppController
5
6 - (id)init
7 {
8 [super init];
9
10 NSLog(@"init");
11
12 speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
13 return self;
14 }
15
16 - (IBAction)sayIt:(id)sender
17 {
18 NSString *string = [textField stringValue];
19 if([string length] == 0)
20 {
21 NSLog(@"string from %@ is of zero-length", textField);
22 return;
23 }
24
25 [speechSynth startSpeakingString:string];
26 NSLog(@"Have started to say: %@", string);
27 }
28
29 - (IBAction)stopIt:(id)sender
30 {
31 NSLog(@"stopping");
32 [speechSynth stopSpeaking];
33 }
34
35 @end
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
2
3
4 @implementation AppController
5
6 - (id)init
7 {
8 [super init];
9
10 NSLog(@"init");
11
12 speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
13 return self;
14 }
15
16 - (IBAction)sayIt:(id)sender
17 {
18 NSString *string = [textField stringValue];
19 if([string length] == 0)
20 {
21 NSLog(@"string from %@ is of zero-length", textField);
22 return;
23 }
24
25 [speechSynth startSpeakingString:string];
26 NSLog(@"Have started to say: %@", string);
27 }
28
29 - (IBAction)stopIt:(id)sender
30 {
31 NSLog(@"stopping");
32 [speechSynth stopSpeaking];
33 }
34
35 @end
转载于:https://www.cnblogs.com/zhtf2014/archive/2011/01/12/1933459.html
相关文章推荐
- Target/Action(Chapter 5 of Cocoa Programming for Mac OS X)
- Core Data Relationships(Chapter 30 of Cocoa Programming for Mac OS X)
- Sheets(Chapter 25 of Cocoa Programming for Mac OS X)
- NSUndoManager(Chapter 9 of Cocoa Programming for Mac OS X)
- Creating NSFormatters(Chapter 26 of Cocoa Programming for Mac OS X)
- Objective-C(Chapter 3 of Cocoa Programming for Mac OS X)
- Images and Mouse Events(Chapter 18 of Cocoa Programming for Mac OS X)
- Drag-and-Drop(Chapter 23 of Cocoa Programming for Mac OS X)
- Memory Management(Chapter 4 of Cocoa Programming for Mac OS X)
- Archiving(Chapter 10 of Cocoa Programming for Mac OS X)
- Custom Views(Chapter 17 of Cocoa Programming for Mac OS X)
- View Swapping(Chapter 29 of Cocoa Programming for Mac OS X)
- NSArrayController(Chapter 8 of Cocoa Programming for Mac OS X)
- Nib Files and NSWindowController(Chapter 12 of Cocoa Programming for Mac OS X)
- Let's Get Started(Chapter 2 of Cocoa Programming for Mac OS X)
- Helper Objects (Chapter 6 of Cocoa Programming for Mac OS X)
- Using Notifications(Chapter 14 of Cocoa Programming for Mac OS X)
- Keyboard Events(Chapter 19 of Cocoa Programming for Mac OS X)
- Web Service(Chapter 28 of Cocoa Programming for Mac OS X)
- Archiving(Chapter 10 of Cocoa Programming for Mac OS X)