簡體   English   中英

索引到函數數組:表達式解析為未使用的l值

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

我試圖索引到一個函數數組但我得到錯誤:“表達式解析為未使用的l值”。 我試圖谷歌這意味着什么,但信息是稀缺的,我發現似乎無關。 有誰知道我在做錯了什么? 任何幫助將非常感激 ! 謝謝。

 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]與僅僅編寫lineChart()結果類似; 你正在識別一個值,但實際上並沒有對它做任何事情。

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