【发布时间】:2016-10-11 02:31:00
【问题描述】:
我是 IOS 编程新手。我用容器视图(ContainerViewController.swift)创建了viewController(ViewController.swift),它有2个视图(FirstViewController.swift和SecondViewViewcontroller.swift),然后我在FirstViewcontroler中添加了按钮并为此添加了@IBAction,但我不能单击按钮(操作不起作用)。在容器视图中添加以下代码
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 按钮不起作用 请帮我解决这个问题。提前感谢您的回复。
【问题讨论】:
-
如果我理解正确,我会在您的 containerViewController 上设置一个委托协议,并使用一个更改它的方法 childVC。然后FirstViewController中的按钮就可以调用那个方法了。
-
你能展示你的故事板吗?
标签: ios swift uibutton uicontainerview