5

How do I access IBOutlets that have been created in another class? For example, if I have an IBOutlet in Class A how can I access in Class B? If I can not access IBOutlets from other classes what is a work-around?

César
  • 9,939
  • 6
  • 53
  • 74
Blake
  • 53
  • 1
  • 3

1 Answers1

10

You'll need to make your IBOutlet a @property and define a getter for that property via @synthesize or you can define your own getter, here's an example of the former:

@interface ClassA : NSObject {
   UIView *someView;
}
@property (nonatomic, retain) IBOutlet UIView *someView;
@end

@implementation ClassA

@synthesize someView;

...

@end

Then, in ClassB, you can do this:

@implementation ClassB 

- (void) doSomethingWithSomeView {
   ClassA *a = [ClassA new];
   UIView *someView = [a someView];
   //do something with someView...
}

...

@end
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320