我是 IOS 编程的新手。我用容器 View (ContainerViewController.swift)创建了 viewController(ViewController.swift),它有 2 个 View (FirstViewController.swift 和 SecondViewViewcontroller.swift),然后我在 FirstViewcontroler 中添加了按钮并为此添加了 @IBAction,但我不能单击按钮(操作不起作用)。在容器 View 中添加以下代码
ContainerViewController.swift
func segueIdentifierReceivedFromParent(button: String){
buttonClick = button
if button == "first"
{
self.segueIdentifier = "firstSegue"
self.performSegueWithIdentifier(self.segueIdentifier, sender: nil)
}
else if button == "second"
{
self.segueIdentifier = "secondSegue"
self.performSegueWithIdentifier(self.segueIdentifier, sender: nil)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == segueIdentifier{
//Avoids creation of a stack of view controllers
if lastViewController != nil{
lastViewController.view.removeFromSuperview()
}
vc = segue.destinationViewController //as! UIViewController
self.addChildViewController(vc)
vc.view.frame = CGRect(x: 0,y: 0, width:self.view.frame.width,height:self.view.frame.height)
self.view.addSubview(vc.view)
vc.didMoveToParentViewController(self)
}
FirstViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func getQuotesAction(sender: UIButton){
print("Button is Clicked")
}
这个 getQuotesAction 按钮不工作 请帮我解决这个问题。预先感谢您的回复。
最佳答案
我通过增加容器 View 的高度解决了这个问题,因为我的第一个 View Controller 高度高于容器 View 。现在, subview Controller 操作工作正常。
关于ios - IOS Swift 中的容器 View 中未触发按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37742873/