SWIFT / IOS 8.2
我试图将CalculatorViewController
设置为委托目标,以便我可以获取数据 - 但我似乎设置错了:“EXC_BAD_ACCESS(code:2)”
(在GraphView.swift中)
protocol CalculatorViewDataSource: class {
func calculateYForXEquals(sender: CalculatorViewController, currentX: CGFloat) ->CGFloat?
}
class GraphView: UIView {
weak var calculatorViewDataSource: CalculatorViewDataSource?
//...
}
(在GraphViewController.swift中)
class GraphViewController: UIViewController {
@IBOutlet weak var graphView: GraphView! {
didSet{
graphView.calculatorViewDataSource = self.view.superview?.superview as CalculatorViewController
}
}
// ...
}
(在CalculatorViewController.swift中)
class CalculatorViewController: UIViewController, CalculatorViewDataSource{
// ...
}
func calculateYForXEquals(sender: CalculatorViewController, currentX: CGFloat) ->CGFloat? {
return nil
}
的问题:
当我尝试在GraphViewController中设置委托时,我遇到了“EXC_BAD_ACCESS(code:2)”错误...有什么想法吗?
我不知道如何从CalculatorViewController
级别上课。
这是故事板:
-> SplitViewController - NavigationController - (Master) CalculatorViewController
I
NavigationController - (Detail) GraphViewController
答案 0 :(得分:0)
尝试做这样的事情:
var graphViewController: GraphViewController?
private func setupSplitViewController() {
let masterNavigationController: AnyObject? = splitViewController?.viewControllers.first
graphViewController = masterNavigationController!.topViewController as? GraphViewController
graphViewController!.graphView.calculatorViewDataSource = self
}