如何使用另一个视图控制器中的xib中的按钮

时间:2018-02-07 14:32:52

标签: ios swift3

我正在使用segmetn控制器并且我放置了一个视图并创建了两个xib,因为段索引更改我更改了xib,但是我想禁用段单击并通过我在每个插入的按钮进行更改xib,但不是我不能做这个改变,也没有我放在按钮内的打印工作。有谁知道我怎么解决它?

我也会发布代码。

这是段控制器的代码。

import UIKit

class SegmentViewController: UIViewController {

    @IBOutlet weak var Segment: UISegmentedControl!
    @IBOutlet weak var containerView: UIView!

    var view1 : UIView!
    var view2 : UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        view1 = primeiraViewController().view
        view2 = segundaViewController().view
        containerView.addSubview(view1)
        containerView.addSubview(view2)

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func testes(_ sender: UISegmentedControl) {

        switch Segment.selectedSegmentIndex {
        case 0:
            containerView.addSubview(view1)
            break
        case 1:
            containerView.bringSubview(toFront: view2)
            break

        default:
            break
        }

    }

}

这是xib代码

import UIKit

class primeiraViewController: UIViewController {

    @IBAction func teste(_ sender: UIButton) {

        print("afjkakfasfa")

    }
    override func viewDidLoad() {
        super.viewDidLoad()


        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

0 个答案:

没有答案