使用另一个类中的对象 [英] Using object from one class in another

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

问题描述

我有一个两个 UIViewControllers ,其中一个我希望显示一个自定义按钮。我已经为此编写了代码。我还将popover segue的代码编写到另一个 ViewController ,并且由于两个控制器都属于我的'ViewController'类,该按钮也显示在第二个 ViewController ,我不想要。

I have a two UIViewControllers, on one of which I want a custom button to be displayed. I have written the code for this. I have also written the code for a popover segue to the other ViewController, and as both controllers belong to my 'ViewController' class, the button is also displayed on the second ViewController, which I do not want.

显然我可以创建另一个类并使我的第二个 ViewController 这个类的成员,但是我想要第二个 ViewController 的代码来改变第一个<$ c $中按钮的颜色c> ViewController ,那么如何在第二类实现文件中使用第一堂课的对象?

Obviously I can create another class and make my second ViewController a member of this class, however I want the code for my second ViewController to change the colour of the button in the first ViewController, so how can I use an object from my first class in the second class implementation file?

推荐答案


我有两个UIViewControllers,其中一个我想要显示一个自定义按钮
。我已经为此编写了代码。我还写了
popover segue到另一个ViewController的代码,因为
控制器都是我的'ViewController'类的子类,按钮是
也显示在第二个ViewController上,我不想要。

I have a two UIViewControllers, on one of which I want a custom button to be displayed. I have written the code for this. I have also written the code for a popover segue to the other ViewController, and as both controllers are subclasses of my 'ViewController' class, the button is also displayed on the second ViewController, which I do not want.

为什么不在第一个cass中将少数属性设为私有,以便它不会被继承。

Why don't you make few property private in first cass so that it doesn't get inherited.


显然我可以创建另一个类并使我的第二个ViewController
a成员这个类,但是我想要第二个
ViewController的代码来改变第一个
ViewController中按钮的颜色,那么如何在
秒中使用第一个类中的对象类实现文件?

Obviously I can create another class and make my second ViewController a member of this class, however I want the code for my second ViewController to change the colour of the button in the first ViewController, so how can I use an object from my first class in the second class implementation file?

您的主要问题是从ClassB 访问ClassA的对象。

Your main problem is to access object of ClassA from ClassB.

这里有很多方法和答案:

Here are a lot of ways, and answers here, to do :

通过不同视图的按钮更新标签

Xcode - 从不同视图更新ViewController标签文本

在另一个班级设置标签文字

设置标记在另一个视图上以存储NSDate

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

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