我正在尝试索引函数数组,但是我得到错误:"表达式解析为未使用的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
}
答案 0 :(得分:10)
chartsArray[0]
类似于只编写lineChart()
的结果;你正在识别一个值,但实际上并没有用它做任何事情。
答案 1 :(得分:1)
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
}