简体   繁体   English

索引到函数数组:表达式解析为未使用的l值

[英]Indexing into array of functions: Expression resolves to an unused l-value

I am trying to index into an array of functions but I get the error: "Expression resolves to an unused l-value". 我试图索引到一个函数数组但我得到错误:“表达式解析为未使用的l值”。 I have tried to google what this means but information is scarce and what I find seems unrelated. 我试图谷歌这意味着什么,但信息是稀缺的,我发现似乎无关。 Does anyone know what I am doing wrong here? 有谁知道我在做错了什么? Any help would be much appreciated ! 任何帮助将非常感激 ! Thank you. 谢谢。

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell:UITableViewCell = myTableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
    var chart =  cell.contentView.viewWithTag(42) as TKChart
    chart.delegate = self
    chart.removeAllData(); //needed because of cell recycling

    var userDef1 = 1
    var userDef2 = 1

    func lineChart() -> TKChart {...}
    func columnChart() -> TKChart {...}

    var chartsArray = [AnyObject]()


    if userDef1 == 1{
        chartsArray.append(lineChart())
    }


    if userDef2 == 1{
        chartsArray.append(columnChart())
    }


     if indexPath.row == 0{
        chartsArray[0]  **error: Expression resolves to an unused l-value**
    }


    if indexPath.row == 1{
        chartsArray[1]   **error: Expression resolves to an unused l-value**
    }

    return cell
}

chartsArray[0] is analagous to writing just the result of lineChart() ; chartsArray[0]与仅仅编写lineChart()结果类似; you're identifying a value, but not actually doing anything with it. 你正在识别一个值,但实际上并没有对它做任何事情。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell:UITableViewCell = myTableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
    var chart =  cell.contentView.viewWithTag(42) as TKChart
    chart.delegate = self
    chart.removeAllData(); //needed because of cell recycling

    var userDef1 = 1
    var userDef2 = 1

    func lineChart() -> TKChart {...}
    func columnChart() -> TKChart {...}

    var chartsArray = [AnyObject]()


    if userDef1 == 1{
        chartsArray.append(lineChart)
   }


    if userDef2 == 1{
        chartsArray.append(columnChart)
    }


     if indexPath.row == 0{
        chartsArray[0]()  
    }


    if indexPath.row == 1{
        chartsArray[1]()   
    }

     return cell
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM