Getting an error connecting to target. Should be simple. Help please.

Joined
Mar 16, 2011
Messages
3
Reaction score
0
Points
1
Hey,

I'm a software developer but and have recently taken up some Objective-C and Cocoa books.

I'm currently on Aaron Hillegaas's Book "Cocoa Programming for Max OS X"

In Chapter 5 he has you go through a simple program on how to create a program utilizing the NSSpeechSynthesizer. You create a text field and two buttons, with the purpose of being able to type in a phrase and then you can press Start or Stop to have the machine read your phrase.

I have found the exact 'Chapter' or 'Code snippet description' here ( Creating a Cocoa AppController Class )


I have followed everything exactly and I get the following error when I build and run.


2011-03-16 22:06:27.010 SpeakLine[1051:a0f] Could not connect the action sayIt: to target of class AppController
2011-03-16 22:06:27.011 SpeakLine[1051:a0f] Could not connect the action stopIt: to target of class AppController

I know my code is likely fine as I was able to find ONE other person having this issue while doing a google search and following this Chapter. However, he never found a solution.

Does anyone know what is the issue with this likely easy issue?
 
Joined
Oct 26, 2009
Messages
128
Reaction score
8
Points
18
Usually you need to register a control with a target. You can do it from code or interface builder. You can checkout the API docs for UIControl. There you will find an addTarget method. That's what you need to call on the control reference to register the callback method (action) with the control. I pasted some sample code so you can see how to call the addTarget method from a controller class.

- (void)setupControls {
[mySlider addTarget:self action:mad:selector(updateVolume)
forControlEvents:UIControlEventValueChanged];
[myButton addTarget:self action:mad:selector(hitOrMiss)
forControlEvents:UIControlEventTouchUpInside];
}
 
OP
C
Joined
Mar 16, 2011
Messages
3
Reaction score
0
Points
1
Awesome, thank you. I will try this when I get home tonight.

Also, how can I do this through Interface Builder? I would love to know that.
 
Joined
Oct 26, 2009
Messages
128
Reaction score
8
Points
18
Don't copy my code, it won't work for you. Your view is different with different controls and variable names. It was meant as an example of how to hook callbacks in your controller to the actual controls generating the events. It's kind of difficult to explain how it works in Interface Builder. I use xcode 4 and the steps I outline are for version 4. The process is similar in xcode 3.

You need to define your controller interface with the appropriate IBOutlet and IBAction tags. They are just markers, technically they don't do anything beyond tagging variables and methods for Interface Builder.

Once that's done, drag a control onto the view object in Interface Builder then open the File's Owner and click the little Arrow icon in the Utilities window. Under Outlets you should see all your outlets defined in your controller class. Click and hold the little circle next to the outlet you want to wire to the control. Drag the blue line on top of the control to hook the control to the instance variable (outlet) in your controller. It's a similar process for the actions. Press and hold the control button on your keyboard and click the control in the view. Drag the blue line to the File's Owner and select the action from the popup menu. Basically you are wiring outlets and actions in the controller class to the control in the view.
 
OP
C
Joined
Mar 16, 2011
Messages
3
Reaction score
0
Points
1
Tutorial

Can anyone point me to a good step by step tutorial on how to create a simple GUI based application?

Chapter 5 of Hillegass' new book doesn't work as others have run into this online, and the other book I have "Learning Cocoa with Objective-C" is quite outdated being written in 2002.
 
Joined
Oct 26, 2009
Messages
128
Reaction score
8
Points
18
There are a few good books on iPhone and Xcode. The only problem is they reference Xcode 3. The process is similar in Xcode 4 but not exactly the same so some deviation is necessary when following the tutorials and not all the screenshots match. I'd start with You Tube. Lots of good videos explain IBOutlet, IBAction and how they work with Interface Builder. The first thing I'd read is the Cocoa Fundamentals Guide.

Cocoa Fundamentals Guide


The Missing Manual series is good. Try iPhone App Development: The Missing Manual for a decent high-level read.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top