【发布时间】:2015-03-13 08:06:40
【问题描述】:
这听起来像是一个奇怪的问题,但我正在尝试实现 BEMSimpleLineGraph 库来生成一些我放在 UITableView 中的图表。我的问题是我如何引用外部数据源和委托以在每个单元格中放置不同的图形(BEMSimpleLineGraph 是在 UITableView 和 UICollectionView 之后建模的)。我目前有这样的事情:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as FlightsDetailCell
cell.userInteractionEnabled = false
if indexPath.section == 0 {
cell.graphView.delegate = GroundspeedData()
cell.graphView.dataSource = GroundspeedData()
return cell
}
if indexPath.section == 1 {
cell.graphView.delegate = self
cell.graphView.dataSource = self
return cell
}
return cell
}
我的第 1 部分的数据源和委托在此下方正确设置,GroundspeedData 类如下所示:
class GroundspeedData: UIViewController, BEMSimpleLineGraphDelegate, BEMSimpleLineGraphDataSource {
func lineGraph(graph: BEMSimpleLineGraphView!, valueForPointAtIndex index: Int) -> CGFloat {
let data = [1.0,2.0,3.0,2.0,0.0]
return CGFloat(data[index])
}
func numberOfPointsInLineGraph(graph: BEMSimpleLineGraphView!) -> Int {
return 5
}
}
由于某种原因,当我运行该应用程序时,Xcode 报告它找不到第 0 节的数据源,特别是“数据源不包含数据。”。我应该如何引用这个备用数据源?
【问题讨论】:
标签: ios swift delegates datasource bemsimplelinegraph