您的位置:首页 > 其它

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


 1 #import "AppController.h"
 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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: