gpt4 book ai didi

iOS 图表,Swift 2.1.1 Xcode 7.2 似乎不起作用,

转载 作者:搜寻专家 更新时间:2023-10-31 22:14:12 26 4
gpt4 key购买 nike

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

情况

X代码 7.2Apple 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

这段代码来自

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

我想要什么

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

我只是通过 StoryBoard 把 window 对象放在了 Viewcontroller 上,并连接为 BarChartView 类。

想要显示条形图,当我更改属性时,“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.
}


}

最佳答案

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

关于iOS 图表,Swift 2.1.1 Xcode 7.2 似乎不起作用,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34672787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com