While I am working on my application, I am faced with a new situation. I am trying to load 2 different graphs [using BEMSimpleLineGraph] each into a different UITableView line. I created a custom cell containing a UIView that inherits from BEMSimpleLineGraphView. My controller species naturally inherits from UIViewController, BEMSimpleLineGraphDelegate, BEMSimpleLineGraphDataSource, UITableViewDataSourceand UITableViewDelegate.
UITableViewDataSource and BEMSimpleLineGraphDataSource have the required methods, but when I declare my methods for viewing the table numberOfRowsInSection and cellForRowAtIndexPath, I can not put the numberOfPointsInLineGraph and valueForPointAtIndex methods inside cellForRowAtIndexPath, because it does not meet the DIMSource BEAM requirements for BEMS.
Here is my current class:
import Foundation
class FlightsDetailViewController: UIViewController, BEMSimpleLineGraphDelegate, BEMSimpleLineGraphDataSource, UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as FlightsDetailCell
cell.userInteractionEnabled = false
cell.graphView.enableBezierCurve = true
cell.graphView.enableReferenceYAxisLines = true
cell.graphView.enableYAxisLabel = true
cell.graphView.colorYaxisLabel = UIColor.whiteColor()
cell.graphView.delegate = self
cell.graphView.dataSource = self
return cell
}
func lineGraph(graph: BEMSimpleLineGraphView!, valueForPointAtIndex index: Int) -> CGFloat {
let data = [1.0,2.0,3.0,2.0,0.0]
let data2 = [2.0,0.0,2.0,3.0,5.0]
return CGFloat(data[index])
}
func numberOfPointsInLineGraph(graph: BEMSimpleLineGraphView!) -> Int {
return 5
}
}
As if, for example, the first graph displayed data from data, and the second displayed graph data from data2. Now my graphs are displayed perfectly, but I can’t figure out how to define independent datasets for each graph. How can I do that?