我爲線圖和條形圖創建了兩個單獨的xib文件,並將其鏈接到場景中的視圖。我根據數據類型分配了筆尖。我在我的UIView類中有一個函數setChart()
,我需要從我的ViewController調用以繪製圖表。從ViewController調用UIView方法
如何從我的ViewController調用函數setChart()
?我的代碼不能正常工作
的UIView:
class BarChartDashboard: UIView {
@IBOutlet weak var barChartView: BarChartView!
override func awakeFromNib() {
.....
}
func setChart(dataPoints: [String], values: [Double]) {
.....
}
}
的ViewController:
class DetailDashboardViewController: UIViewController {
@IBOutlet weak var chartView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
runQueries(2)
if index != 3{
chartView = NSBundle.mainBundle().loadNibNamed("BarChartDashboard", owner: self, options: nil)[0] as? UIView
}
else{
chartView = NSBundle.mainBundle().loadNibNamed("LineChartDashboard", owner: self, options: nil)[0] as? UIView
}
}
}
private extension DetailDashboardViewController {
func runQueries(period: Int) {
self.query(false, periodIndex: period){ (success) -> Void in
if success {
// do second task if success
dispatch_async(dispatch_get_main_queue(), {
if self.index != 3{
(self.chartView as! BarChartDashboard).setChart(self.yAxis, values: self.xAxis)
}
else{
(self.chartView as! LineChartDashboard).setChartData(self.yAxis, yAxisMax: self.xAxisMax, yAxisMin : self.xAxisMin)
}
})
}
}
}
func query(min: Bool, periodIndex: Int, completion: (success: Bool) -> Void) {
.......
}
}