从另一个ViewController调用方法 [英] Calling method from another ViewController

查看:128
本文介绍了从另一个ViewController调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ViewControllerA和一个ViewControllerB。我想从ViewControllerB调用ViewControllerA的方法。

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

在ViewControllerA中有一个方法:

In ViewControllerA is present a method:

  -(NSMutableArray*) loadData;

在ViewControllerB.h中:

In ViewControllerB.h:

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

在ViewControllerB.m中:

In ViewControllerB.m:

self.mutableArray =[viewControllerA loadData];

但该方法未调用。为什么?提前致谢

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

推荐答案

您缺少

self.

只要在viewControllerB中的某个地方:

As long as somewhere in viewControllerB:

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

然后:

self.mutableArray =[self.viewControllerA loadData];

将有效。

这篇关于从另一个ViewController调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆