【发布时间】:2014-12-14 00:36:43
【问题描述】:
我正在尝试快速使用核心情节,除了一个错误外,我感觉非常接近。到目前为止,我的代码是:
class ViewController: UIViewController, CPTPlotDataSource {
@IBOutlet weak var graphView: CPTGraphHostingView!
override func viewDidLoad() {
super.viewDidLoad()
// create graph
var graph = CPTXYGraph(frame: CGRectZero)
graph.title = "Hello Graph"
graph.paddingLeft = 0
graph.paddingTop = 0
graph.paddingRight = 0
graph.paddingBottom = 0
// hide the axes
var axes = graph.axisSet as CPTXYAxisSet
var lineStyle = CPTMutableLineStyle()
lineStyle.lineWidth = 0
axes.xAxis.axisLineStyle = lineStyle
axes.yAxis.axisLineStyle = lineStyle
// add a pie plot
var pie = CPTPieChart()
pie.dataSource = self
pie.pieRadius = (self.view.frame.size.width * 0.9)/2
graph.addPlot(pie)
self.graphView.hostedGraph = graph
}
func numberOfRecordsForPlot(plot: CPTPlot!) -> UInt {
return 4
}
func numberForPlot(plot: CPTPlot!, field fieldEnum: UInt, recordIndex idx: UInt) -> NSNumber! {
return idx+1
}
}
我得到的错误来自:var pie = CPTPieChart()我的错误是:
核心图快速出现错误:“调用中的参数‘frame’缺少参数”
我正在学习一个教程,可能 swift 已经改变了,但是我是这门语言的新手,似乎无法解决这个问题。提前致谢。
【问题讨论】:
-
那么你需要添加一个 CGRect 作为框架参数