问题
I built in a segmented control in Swift 4 using the TwicketSegmentedControl-Framework (find it here on GitHub). My storyboard looks like this:
I added three container views – home, profile and settings –, each with a corresponding VC.swift-file, which are switched through by the segmented control. This is working well, however, any buttons implemented in one of the three views won't work, can't be pressed even.
Do you have a clue why that might be?
My ViewController.swift-file, in which the segmented control sits looks like this: ViewController.swift on GitHub.
I included a button in the first view, "HOME", created an outlet in the corresponding HomeVC.swift-file.
回答1:
You can use observer pattern here in button Action put the below code
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "callForAlert"), object: nil)
In your VC.swift in viewDidLoad() method put below code
NotificationCenter.default.addObserver(self, selector: #selector(hideContainerView), name: NSNotification.Name(rawValue: "callForAlert"), object: nil)
Where hideContainerView is the function which I have created for hiding the container view
来源:https://stackoverflow.com/questions/46427155/button-in-container-view-not-working