Accessing objects from another class

kainjow

Registered
OK, I've got a text field that's defined and used in one class, but I want the app's class to access this for putting the user defaults data into it. But, I can't get it to work. I thought importing the the class into the app's class would do it, but it won't work. Any suggestions?

Thanks.

(I have one window with different NSViews that each have their own contentView and each NSView has it's own class controller. I want the application's main class to access the text field that is controlled by another class)
 
You must first instantiate the class that you are trying to use. In java, you instantiate the class to pass it arguments. You need to have a constructor, accessor, and mutator for the class you want to instantiate. Then you can access the objects in the class you want to use.

Did I make any sense...?

P.S. Been a while since I programmed so take my advice with a grain of salt.
 
There's a couple of ways to do this. You could have your class containing the text field to call a method off the other class that where one of the parameters is the text field object. You could also add a method to the your class containing the text field that returns the text field reference (if your app class has a reference to your other class. Additionally, if you instantiate both your classes in IB, you can just have the same text field be outlets for the different classes. Alos, you could use the notification center if you want and have the app class "listen" for the posting of a notification with your specified name and containing the text field.

Just keeping your options open (I think IB is the way to go, personally):)
F-bacher
 
Back
Top