iOS Charts , Swift 2.1.1 Xcode 7.2 好像不行,

iOS Charts , Swift 2.1.1 Xcode 7.2 seems doesn't work,

我在 2 周内遇到了麻烦,所以请让我提问。

情况

XCode 7.2 Apple Swift 版本 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81) https://github.com/yosuke1985/ios-charts

iOS 图表 ttps://github.com/danielgindi/ios-charts

此代码来自

ttp://www.appcoda.com/ios-charts-api-tutorial/

我想要的

I want to use this framework, but error is EXEC_BAC_ACCESS,

我只通过 StoryBoard 将 window 对象放在 Viewcontroller 上, 并连接为 BarChartView Class.

想要显示条形图, 当我更改属性时,"noDataText" 和 "noDataTextDescription" 它不起作用,也无法找出错误的来源。

    barChartView.noDataText = "there is no data"
    barChartView.noDataTextDescription = "give me the reason"

只有这些代码不起作用, 我开始认为问题来自 Swift 或 XCode 的版本? 请给我解决这个问题的建议。

错误

EXEC_BAC_ACCESS ERROR, Screen Shot

import UIKit
import Charts

class ViewController: UIViewController {
var months: [String]!


@IBOutlet weak var barChartView: BarChartView!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    barChartView.noDataText = "there is no data"
    barChartView.noDataTextDescription = "give me the reason"
    self.months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]

    setChart(months, values: unitsSold)
}


func setChart(dataPoints: [String], values: [Double]) {
    barChartView.noDataText = "You need to provide data for the chart."


    var dataEntries: [BarChartDataEntry] = []

    for i in 0..<dataPoints.count {
        let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
        dataEntries.append(dataEntry)
    }

    let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
    let chartData = BarChartData(xVals: months, dataSet: chartDataSet)
    barChartView.data = chartData
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

已解决。您需要设置条形图视图的 Class 以让 Storyboard 知道要初始化哪个 class。 Custom class 现在为空,这意味着它将被初始化为 UIView 并用作 BarChartView。 参见 http://i.imgur.com/c4tLNjL.png