Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling method from another ViewController

I have a ViewControllerA and a ViewControllerB. I want calling a method of ViewControllerA from ViewControllerB.

In ViewControllerA is present a method:

  -(NSMutableArray*) loadData;

In ViewControllerB.h:

 #import "ViewControllerA.h"
  .......
 @property (nonatomic, strong) ViewControllerA * viewControllerA;
 @property (nonatomic, strong) NSMutableArray * mutableArray;

In ViewControllerB.m:

self.mutableArray =[viewControllerA loadData];

but the method is not calling. Why? Thanks in advance

like image 271
Adriana Carelli Avatar asked Oct 12 '12 09:10

Adriana Carelli


2 Answers

You are missing

self.

As long as somewhere in viewControllerB:

self.viewControllerA = [[viewControllerA alloc]init];  //or some other initialization occurs...

then:

self.mutableArray =[self.viewControllerA loadData];

will work.

like image 152
Piotr Tomasik Avatar answered Nov 02 '22 17:11

Piotr Tomasik


Make sure that the method loadData is specified in viewControllerB's header file.

- (void)loadData;

After than, you can now call the method loadData.

[viewControllerA loadData];
like image 21
KarenAnne Avatar answered Nov 02 '22 18:11

KarenAnne