Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用[indexPath.section][indexPath.row]对下标的使用不明确_Ios_Arrays_Swift_Swift2_Ambiguous - Fatal编程技术网

Ios 使用[indexPath.section][indexPath.row]对下标的使用不明确

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)

在我更新到Xcode 7.2后,出现了一个错误,指出在以下位置下标的使用不明确:

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中没有抱怨