在我的 ViewController 中,我创建了一个 View ,其中包含一个按钮和一堆其他元素。当按下按钮时,我想从父 ViewController 调用一个方法。我试过:
[self.superview buttonPressedMethod];
但是 superview 不是 ViewController 而是 UIView。有办法做到这一点吗?
最佳答案
这正是目标/行动机制的用途。使 View Controller 中的方法成为 IBAction。将 View Controller 设置为按钮的目标,并将方法设置为其操作。这应该是您需要做的全部。
关于objective-c - 从 subview 调用 View Controller 中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7677222/