How to access IBOutlets from other classes in Objective-C?

How do I access IBOutlets that were created in another class? For example, if I have an IBOutlet in Class A , how can I access Class B ? If I cannot access IBOutlets from other classes, what is a workaround?

+4
source share
1 answer

You need to do an IBOutlet a @property and define a getter for this property via @synthesize or you can define your own getter, here is an example of the first:

 @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 
+11
source

Source: https://habr.com/ru/post/1340491/


All Articles