Button in container view not working

泄露秘密 提交于 2019-12-25 19:05:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!