How Do I Access IBOutlets From Other Classes in Objective-C?

☆樱花仙子☆ 提交于 2019-12-01 05:51: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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!