【发布时间】:2015-12-28 01:52:34
【问题描述】:
我对如何正确使用容器视图有点困惑,我会尽力解释它。
我有一个具有动画功能的主视图控制器。
import UIKit
class MainViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
// Run view setups
override func viewDidLoad() {
super.viewDidLoad()
}
func closePicker(){
self.view.layoutIfNeeded();
UIView.animateWithDuration(0.5, animations: {
self.countryPickerConst.constant = -206;
self.view.layoutIfNeeded();
})
}
}
在界面生成器中,我添加了一个带有新视图控制器的容器视图,其中包含一个按钮,如下所示:
import UIKit
class ContainerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func runAnimation(sender: UIButton) {
//I want to call the function in my other view controller
}
}
在 runAnimation 动作中,我想调用 MainViewController 中的函数。如果我只是创建 MainViewController 的一个实例并调用该函数,它似乎失去了它的“自我”相关性。
如果有人可以向我解释做这样的事情的最佳做法,那就太好了。
谢谢
【问题讨论】: