Hi all,
On page 90 of AH (3rd ed) there is a "For the more curious" section. The section demonstrates how to implement "Setting the target Programmatically".
I had initially just accepted this bit of information, but then a reader had tried to implement this and like myself, run into a dead end.
Here is the setup to "set the action of a button to the method" sayIt. (The chapter introduces an application that speaks a line of text). The code seems simple enough.
The code to find a selector from from an NSString at runtime also seems simple.
But, trying to implement this is not as easy ---for me at least.
So, specifically, where would one place the above code? ( The "SpeakLine" application is essentially a window with 2 buttons (StartSpeaking) and (Stop) and an NSTextField that holds the string to be spoken PLUS an object ( the AppController) that has the outlet to the NSTextField and defines the above two methods). I am assuming ( perhaps incorrectly) that this could be implemented in this application?
If that is too vague, ( and it probably is) a few pointers as to how to implement this would be appreciated.
Thanks in advance.
On page 90 of AH (3rd ed) there is a "For the more curious" section. The section demonstrates how to implement "Setting the target Programmatically".
I had initially just accepted this bit of information, but then a reader had tried to implement this and like myself, run into a dead end.
Here is the setup to "set the action of a button to the method" sayIt. (The chapter introduces an application that speaks a line of text). The code seems simple enough.
Code:
SEL mySelector;
mySelector = @selector(sayIt:);
[myButton setAction: mySelector];
The code to find a selector from from an NSString at runtime also seems simple.
Code:
SEL mySelector;
mySelector = NSSelectorFromString(@"sayIt");
[myButton setTarget:someObjectWithAsayItMethod];
[myButton setAction:mySelector];
But, trying to implement this is not as easy ---for me at least.
So, specifically, where would one place the above code? ( The "SpeakLine" application is essentially a window with 2 buttons (StartSpeaking) and (Stop) and an NSTextField that holds the string to be spoken PLUS an object ( the AppController) that has the outlet to the NSTextField and defines the above two methods). I am assuming ( perhaps incorrectly) that this could be implemented in this application?
If that is too vague, ( and it probably is) a few pointers as to how to implement this would be appreciated.
Thanks in advance.