首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在BEMSimpleLineGraph中设置UITableView图

在BEMSimpleLineGraph中设置UITableView图
EN

Stack Overflow用户
提问于 2015-01-12 01:40:28
回答 1查看 1.1K关注 0票数 4

今天晚上在我的应用程序上工作时,我遇到了一个新的情况。我试图使用BEMSimpleLineGraph加载两个不同的图,每个图都加载到UITableView的不同行中。我已经创建了一个包含从UIView继承的BEMSimpleLineGraphView的自定义单元格。我的视图控制器自然继承自UIViewControllerBEMSimpleLineGraphDelegateBEMSimpleLineGraphDataSourceUITableViewDataSourceUITableViewDelegate

UITableViewDataSource和BEMSimpleLineGraphDataSource都有必需的方法,但是当我声明表视图的numberOfRowsInSection和cellForRowAtIndexPath方法时,我不能将numberOfPointsInLineGraph和valueForPointAtIndex方法放在cellForRowAtIndexPath中,因为这不符合BEMSimpleLineGraphDataSource的要求。

这是我现在的班级:

代码语言:javascript
复制
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
}
}

例如,我将如何让第一个图形显示来自data的数据和第二个图形显示来自data2的数据。我的图表现在显示得很好,但我不知道如何为每个图定义独立的数据集。这是如何做到的呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-27 22:42:44

您需要检查图形的哪个实例正在调用数据源/委托。您可以通过将数据源/委托方法中包含的参数lineGraph与图的实例进行比较来找到答案。

我对斯威夫特还不够熟悉,在这里你可以在目标C中做到这一点。

代码语言:javascript
复制
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index 
{
    if ([graph isEqual:self.myGraph1])
    {
        return data;
    }
    else
    {
        return data2;
    }
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27894214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档