1. NSControl is the parent of all controls, NSControl inherits from NSView, so nscontrol is a nsview that can respond to events independently, each nscontrol containing a target and action, The action message is sent when the user interacts with the control.
One thing you don't understand is that most of the controls in iOS have been notified to the caller by the method that called the corresponding protocol, and NSControl has only one action, which is understandable for a button, and how should it respond to a table?
2. Implement Speakline Demo
:
Create a new empty project, automatically set up a window in the project
Create a new Viewcontroller and add Viewcontroller.view to the Contentview of the window
The code is as follows:
Appdelegate:
-(void) applicationdidfinishlaunching: (nsnotification *) anotification { // [Self.window SetBackgroundColor : [NSColor Redcolor]]; _SPVC = [[Spviewcontroller alloc] initwithnibname:@ "Spviewcontroller" bundle:nil]; _spvc.view.frame = nsmakerect (0, 0, self.window.frame.size.width, self.window.frame.size.height); _spvc.view.autoresizingmask = nsviewwidthsizable| nsviewheightsizable; [Self.window.contentView Addsubview:_spvc.view]; Self.window.title = @ "Speak line"; }
VC corresponding to the code:
#import "SPViewController.h" @interface Spviewcontroller () @property (weak) Iboutlet Nstextfield *speaktextfield;@ Property (Nonatomic, Strong) Nsspeechsynthesizer *speechsynth; @end @implementation spviewcontroller-(void) viewdidload { [super viewdidload]; Do view setup here. _speechsynth = [[Nsspeechsynthesizer alloc] init];} -(Ibaction) STOP: (ID) Sender { [_speechsynth stopspeaking];} -(Ibaction) Speak: (ID) Sender { if (_speaktextfield.stringvalue.length > 0) { [_speechsynth Startspeakingstring:_speaktextfield.stringvalue]; } } @end
Code Address: http://pan.baidu.com/s/1ntpAR37
Cocoa®programming for Mac®os X (2)-Speak line