我有一个带有自定义单元格的可扩展表格,当点击可见行时,这些单元格会出现或消失。单元格的数据存储在 plist 中并声明为 NSMutableArray。
我在以下代码中遇到“下标使用不明确”错误,希望其他人遇到过此问题并知道修复方法。 我已经尝试了所有可能的选项,据我所知,我必须添加。
var cellDescriptors: NSMutableArray!
func getCellDescriptorForIndexPath(indexPath: NSIndexPath) -> [String: AnyObject] {
let indexOfVisibleRow = visibleRowsPerSection[indexPath.section][indexPath.row]
let cellDescriptor = cellDescriptors[indexPath.section][indexOfVisibleRow] as! [String: AnyObject]
return cellDescriptor
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indexOfTappedRow = visibleRowsPerSection[indexPath.section][indexPath.row]
if cellDescriptors[indexPath.section][indexOfTappedRow]["isExpanded"] as! Bool == true { // Ambiguous use of subscript error
var shouldExpandAndShowSubRows = false
if cellDescriptors[indexPath.section][indexOfTappedRow]["isExpanded"] as! Bool == false { // Ambiguous use of subscript error
// In this case the cell should expand.
shouldExpandAndShowSubRows = true
}
最佳答案
Cor,我假设你现在已经解决了这个问题,但在找到解决方案后,我想我会提请你注意:
func getCellDescriptorForIndexPath(indexPath: NSIndexPath) -> [String: AnyObject] {
let indexOfVisibleRow = visibleRowsPerSection[indexPath.section][indexPath.row]
// HERE IS WHAT YOU WANT:
let cellDescriptor = (cellDescriptors[indexPath.section] as! NSMutableArray)[indexOfVisibleRow] as! [String: AnyObject]
return cellDescriptor
}
关于ios - 下标使用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33915840/