If I create a new instance of a class with IB I can't send messages to it because I don't know its name. I have asked several people and they always say 'you just use files owner' but that doesn't answer my question. What is the instances name?
views:
225answers:
3In order to send a message to an object you created in IB, you have to hook it up to something's outlet. For example, if you create an instance of MyObject, you'll be able to reference it by creating an out let in your file's owner that points to MyObject, and hooking it up.
//Header file
@interface MyViewController : UIViewController {
MyObject *_myObjectOutlet;
}
@property (nonatomic, readwrite, retain) IBOutlet MyObject *myObjectOutlet;
@end
//Implementation file
@implementation MyViewController
@synthesize myObjectOutlet = _myObjectOutlet;
...
Then, in your IB file, create an instance of MyObject, set the file owner to be an instance of MyViewController, and hook that object's myObjectOutlet up to your MyObject.
Objects don't have names (NS/UIImages excepted, but that's different). In order to refer to an object in a nib by name, you must have an instance variable with that name, make that instance variable an outlet (with the IBOutlet
keyword), and connect the outlet to the object in IB.
It sounds like you're new, so you should run through Apple's Currency Converter tutorial and make sure you're up to speed on IBOutlets and how they work. They're the pointers you use to access the objects in a nib file.