返回所有数组的索引swift

时间:2015-02-28 11:18:31

标签: swift

我的实体中有一个activityPercentage列表,我将所有值迭代为CGFloat。但是下面的代码只占用chartData数组中的最后一个值。

截图: https://www.dropbox.com/s/d1b5e6xlle4ivqp/Screenshot%202015-02-28%2014.02.06.png?dl=0

func barChartView(barChartView: JBBarChartView!, heightForBarViewAtIndex index: UInt) -> CGFloat {

        var activityPers: Int?
        for activity in chartData{
            activityPers = activity.activityPercentage as? Int
        }
        return CGFloat(activityPers!)

    }

请帮助,我想要返回每个栏中的所有百分比,而不仅仅是最后输入的activityPercentage。

如何将此行存储在Array中,因为我需要一个数组变量来访问下标索引

activityPers = activity.activityPercentage as? Int

2 个答案:

答案 0 :(得分:0)

您只需要为请求的index返回高度。对于每个条形,将为index使用不同的值单独调用该方法。

答案 1 :(得分:0)

得到了它!

 var data: NSManagedObject = chartData[Int(index)] as NSManagedObject

    var percentageFloat = data.valueForKeyPath("activityPercentage") as Int
    return CGFloat(percentageFloat)
相关问题