点击addsubview事件按钮

时间:2018-07-10 03:16:06

标签: ios

我在名为UIViewControllerB的子视图中有一个按钮。教我如何在UIViewControllerB中捕获单击事件的人将在UIViewcontroller A字符串下的UIView中添加新视图作为我的代码。

这是ViewControllerB中显示在UIViewController A的UIView中的按钮

@IBAction func button_complate(sender: AnyObject) {
NSLog("aaa", "bbb")
}

这是包含UIViewControllerA的{​​{1}}

UIView

1 个答案:

答案 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()
    }

}