iphone - 在另一个类中使用一个类的对象

标签 iphone ios objective-c xcode ipad

我有两个 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

Setting label text in another class

Set label on another view to stored NSDate

关于iphone - 在另一个类中使用一个类的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15187241/

相关文章:

ios - 为iPhone和iPad开发同一个应用程序:针对每种设备类型针对所有应用程序开发一个应用程序还是针对两个应用程序开发两个应用程序?

ios - 转换为最新语法时出现错误 "swiftc failed with exit code 1"

iphone - UIButton 标题上方的中心图像

ios - 将 UIView 添加到 tableFooterView 时 UITableView 抛出异常

ios - 多个自定义 UITableViewCell

ios - 如何使用自动布局从 Storyboard 中制作动态 y 位置

objective-c - 什么时候在变量定义中使用 *(在 Objective-C 中)?

iphone - 如何同时从iPhone中的URLS解析XML

iphone - 如何将 x 个 UIImages 连接在一起?

ios - 使用自定义模式 UIViewControllerTransitioningDelegate 进行旋转