ios - IOS Swift 中的容器 View 中未触发按钮操作

标签 ios swift uibutton uicontainerview

enter image description here我是 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/

相关文章:

ios - 通过比较字符串值快速对数组进行排序

ios - 进入applicationWillEnterForeground后如何刷新View?

ios - UIAlertView 未返回适当的值

ios - 自定义形状可触摸区域

ios - 如何使用 Swift 3 在本地化条件下更改按钮字体大小

ios - 快速将对象添加到 AnyObject

ios - swift iOS : Get the title of current song playing

ios - localizedCaseInsensitiveContainsString 在 Swift 中不可用

ios - 如何向所有 UIViewControllers 添加一个通用的 float 操作按钮

ios - 如何以编程方式将按钮定位到带有边距的表格单元格的最右边缘?