无法访问其他类的对象 [英] Unable to access object of other class

查看:89
本文介绍了无法访问其他类的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问另一个类中的一个类的对象。但是实例变量显示为空。

I am accessing object of one class in the another class. But instance variable is Showing null.

这是我的代码。

fvcObj = [[FirstViewController alloc]init];
NSLog(@"%@",fvcObj.user);

在声明另一个类的对象时需要注意哪些事项?
谢谢。

Which things to take care in declaring object of another class? Thanks.

推荐答案

正如PengOne所说,它是FirstViewController类的新实例,它无法保存数据你已经在FirstViewController类中使用了user变量。我想你想将数据从一个视图控制器类传递给另一个。如果是,则在要向其发送数据的类中声明一个方法,并从另一个类中调用此方法,并将数据作为方法的参数传递。
希望这可能会对你有所帮助。
快乐编码

As PengOne has said it is a new instance of the class FirstViewController and it cannot hold the data which you have assinged to the "user" variable in FirstViewController class. I think you want to pass data from one view controller class to other. If so then declare a method in the class to which you want to send the data and call this method from the other class and pass the data as a parameter of the method. Hope this might help u. Happy coding

这篇关于无法访问其他类的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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