ios - 下标使用不明确

标签 ios swift uitableview nsmutablearray

我有一个带有自定义单元格的可扩展表格,当点击可见行时,这些单元格会出现或消失。单元格的数据存储在 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/

相关文章:

ios - 在 ViewController 中将 API 数据发送到 UITableView

swift - 为 Struct 声明 let 和为其属性声明 var 之间有什么区别,反之亦然?

ios - 编辑时tableView中没有didSelectRowAtIndexPath()

iphone - 如何知道单元格是否位于部分中的第一个

ios - 在 UITableview 中进行多项选择时遇到问题

ios - CLLocationManager startMonitoringForRegion 限制

ios - IQKeyboardManager 错误 : Value of type 'UIView' has no member 'keyboardToolbar'

swift 4 : Add pencil to sign PDF file

objective-c - 静态 UITableView 中的自定义 UITableViewCell

ios - 在 UITableView 中显示 2D 数组