我有两个 UIViewController
,我希望在其中一个上显示一个自定义按钮。我已经为此编写了代码。我还编写了到另一个 ViewController
的弹出窗口 Segue 的代码,并且由于两个 Controller 都属于我的“ViewController”类,因此该按钮也显示在第二个 ViewController
上,这是我不想要的。
显然,我可以创建另一个类并使我的第二个 ViewController
成为此类的成员,但是我希望我的第二个 ViewController
的代码更改按钮的颜色在第一个 ViewController
中,那么如何在第二个类 implementation
文件中使用第一个类中的对象?
最佳答案
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.
为什么不在第一个 cas 中将一些属性设为私有(private),这样它就不会被继承。
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 的对象。
这里有很多方法和答案:
Update a label through button from different view
Xcode - update ViewController label text from different view
关于iphone - 在另一个类中使用一个类的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15187241/