|Jun 15, 2009, 09:53 AM||#1|
Hillegass Page 90 FTMC "Setting the target Programmatically"
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.
SEL mySelector; mySelector = @selector(sayIt:); [myButton setAction: mySelector];
SEL mySelector; mySelector = NSSelectorFromString(@"sayIt"); [myButton setTarget:someObjectWithAsayItMethod]; [myButton setAction:mySelector];
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.
|Jun 15, 2009, 06:15 PM||#2|
I'm not sure I understand exactly, but it seems odd to have two buttons for start and stop (speaking). Wouldn't it make more sense to have a single button that toggles between start and stop? If the action of the button doesn't need to change throughout the program, you'd probably implement it in awakeFromNib: in your AppController object (where all UI elements in the .nib/.xib file are guaranteed to be valid). Of course it'd be easier to just connect it in IB but that's not the point here. If it does need to change (the reason you might want to be setting it programmatically), then you just put the code wherever it makes sense to change it. For example, if you had the single button toggle model, connect that button to an IBAction method startSpeaking: (because speaking will be off when the app launches). Inside startSpeaking: you would set the button action to stopSpeaking: and do the opposite inside that method.
Go outside, the graphics are amazing!
|Jun 15, 2009, 07:06 PM||#3|
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|All iPads: FYI - Target offering $200 store GC for "any" iPad trade-in||jasonv1||iPad||84||Nov 10, 2013 10:41 AM|
|Need help setting "home" and "work" locations correctly||dk143||iOS 6||4||Jun 23, 2013 08:03 PM|
|Thunderbolt and possible "Target Disk Mode" transfer||alexglee||MacBook Pro||2||Nov 19, 2012 10:49 AM|
|How i can fix "Wiki setting error" and "Running time error" ?||Amethyst||Mac OS X Server, Xserve, and Networking||0||Sep 2, 2012 02:34 PM|
|I forgot to set the version of "deployment target".||fabiogc||iPhone and iPod touch Apps||0||Aug 31, 2012 11:24 AM|
All times are GMT -5. The time now is 04:40 AM.