Ios 使用[indexPath.section][indexPath.row]对下标的使用不明确
在我更新到Xcode 7.2后,出现了一个错误,指出在以下位置下标的使用不明确:Ios 使用[indexPath.section][indexPath.row]对下标的使用不明确,ios,arrays,swift,swift2,ambiguous,Ios,Arrays,Swift,Swift2,Ambiguous,在我更新到Xcode 7.2后,出现了一个错误,指出在以下位置下标的使用不明确: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
/*ERROR - Ambiguous use of subscript*/
cell.textLabel?.text = self.tvArray[indexPath.section][indexPath.row] as? String
//..... more code
}
有谁能告诉我在实现tvArray时我做错了什么
设置:
无显式类型的tvArray=[]被推断为[AnyObject]
告诉编译器数组的正确类型:包含字符串数组的数组。
然后它知道数组可以被索引下标
var tvArray = Array<[String]>()
附加好处:不需要在CellForRowatineXpath中进行类型转换
cell.textLabel?.text = self.tvArray[indexPath.section][indexPath.row]
无显式类型的tvArray=[]被推断为[AnyObject]
告诉编译器数组的正确类型:包含字符串数组的数组。
然后它知道数组可以被索引下标
var tvArray = Array<[String]>()
附加好处:不需要在CellForRowatineXpath中进行类型转换
cell.textLabel?.text = self.tvArray[indexPath.section][indexPath.row]
谢谢,我想我忘了那部分了。奇怪的是编译器没有在7.1:0版本中抱怨。我想我忘了那部分。奇怪的是编译器在7.1:0中没有抱怨