我正在使用自定義tableview單元格中的iOS-Charts中的線形圖表進行觸摸擴展。我沒有加載cellForRow中的圖表:因爲這加載了所有單元格中的所有圖表並且殺死了滾動性能,所以我在didSelectRow中加載了它:問題是,出於某種原因,圖表不會在用戶第一次觸及單元格時加載,我不知道爲什麼。另外,當展開的單元格(當前正在顯示圖表)被摺疊時,似乎圖表動畫開始。如何重置tableview單元格中的iOS-Charts動畫
這是我的didSelectRow:下面是我的自定義單元格中的圖表功能。我一直在與這個摔跤,任何有識之士將不勝感激!
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell:CandDetailTableViewCell = tableView.cellForRowAtIndexPath(indexPath) as! CandDetailTableViewCell
// CALLS METHOD TO BUILD CHART WITH DATA I SAVED IN THESE ARRAYS
cell.setChart(dataForMonths, values: dataForRatings)
let previousIndexPath = selectedIndexPath
if indexPath == selectedIndexPath {
// if user taps cell that was already selected so it collapses
selectedIndexPath = nil
} else {
// when user selects new cell
selectedIndexPath = indexPath
}
var indexPaths:Array <NSIndexPath> = []
if let previous = previousIndexPath {
indexPaths += [previous]
}
if let current = selectedIndexPath {
indexPaths += [current]
}
if indexPaths.count > 0 {
tableView.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic)
}
tableView.scrollRectToVisible(tableView.rectForRowAtIndexPath(indexPath), animated: true)
}
這裏是圖FUNC在實現代碼如下細胞:
func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
dataEntries.append(dataEntry)
}
let lineChartDataSet = LineChartDataSet(yVals: dataEntries, label: "Rating")
let lineChartData = LineChartData(xVals: dataPoints, dataSet: lineChartDataSet)
analyticsView.data = lineChartData
analyticsView.xAxis.labelPosition = .Bottom
analyticsView.backgroundColor = UIColor.whiteColor()
analyticsView.userInteractionEnabled = false
analyticsView.drawGridBackgroundEnabled = false
analyticsView.drawBordersEnabled = false
analyticsView.leftAxis.enabled = false
analyticsView.rightAxis.enabled = false
analyticsView.xAxis.gridLineWidth = 0.0
analyticsView.xAxis.axisLineColor = UIColor.clearColor()
analyticsView.legend.enabled = false
// Removes the description text off the chart
analyticsView.descriptionText = ""
analyticsView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
}
我改變了'analyticsView.data = lineChartData 「在建立圖表視圖後最終結束;它仍然運行相同。當我在didSelectRow中調用'cell.setChart(dataForMonths,values:dataForRatings)'時添加圖表視圖,並顯示在我的單元格中的UIView中。 – tahoecoop
然後你應該在drawRect被調用時開始調試 – Wingzero