Access a IBOutlet id defined in one class in another

66 views Asked by At

Hello I have an IBOutlet id which is used for a view it's defined in a class, I need to access it from another class how can I do this?

I'm still learning ObjC so I appreciate your patience with me as i'm trying to learn as much as possible!

To add more context: I have a controller which is where my view IBOutlet is defined, I then have a class which does some drawing - I need to use dataWithPDFInsideRect on the view from the other class as part of my drawing.

I've so far i've created an instance of the controller but not sure how to access the IBOutlet from that.

MyController *saveTextViewController = [[MyController alloc] init];

1

There are 1 answers

0
Scott Thompson On

IB Outlets are used to link information created from a ".xib" file to runtime values in your code. If your MyController would only have an IBOutlet value if you intended to create an instance of it by loading it from an interface builder file, not create it with alloc and init.

If you did load MyController from the xib file, and in that xib file the outlet was linked to another view that was also loaded from the xib file then at runtime the value of the outlet would be set to the second view automatically.

Read the documentation on:

Connecting Objects to Code