Vix Hunk Vix Hunk - 3 months ago 7
Objective-C Question

How can i get data from my mainViewcontroller when subview is present

i have a MainViewController and multiple SubViews in it. i have a NSMutableArray in my MainViewController but i need it inside my SubView so how can i access that mutablearray from my subview when it is present as a child of MainViewController?

Answer

Simply create an array property in your subview class and pass the array from your main viewcontroller to your subview class when you initialise your subview.

Code in your main viewcontroller:

YourSubviewClass *subView = [[YourSubview alloc] init];
subView.array = self.yourMainViewControllArray

Code in your subview class header file:

@interface YourSubviewClass : UIView

@property (nonatomic) NSMutableArray *array;

Hope this helps, good luck.