我在名为UIViewControllerB
的子视图中有一个按钮。教我如何在UIViewControllerB中捕获单击事件的人将在UIViewcontroller
A字符串下的UIView中添加新视图作为我的代码。
这是ViewControllerB
中显示在UIViewController A的UIView中的按钮
@IBAction func button_complate(sender: AnyObject) {
NSLog("aaa", "bbb")
}
这是包含UIViewControllerA
的{{1}}
UIView
答案 0 :(得分:-1)
尝试代码:
class UIViewControllerA: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
func addView(/*param */) {
// do something
}
// when push to UIViewControllerB set install for viewcontrollerA
private func goToScreenB(){
let viewB = UIViewControllerB()
viewB.viewcontrollerA = self
self.navigationController?.pushViewController(viewB, animated: true)
}
}
class UIViewControllerB: UIViewController {
// In UIViewControllerB create a install of UIViewControllerA
var viewcontrollerA : UIViewControllerA?
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func button_complate(sender: AnyObject) {
self.viewcontrollerA?.addView()
}
}