ios - -[__NSCFNumber 行] : unrecognized selector sent to instance

标签 ios swift realm

我已经检查了其他答案,但他们似乎没有正确回答我的问题。如果有明显的我没见过的,请帮我把它放在评论中:)

我有一个 tableView,它有一个 Realm 数据库作为数据源。我希望能够从源中删除已删除的单元格。

代码如下:

func objectsForSection(section: UInt) -> RLMResults {
    let categoryName = (Category.allObjects()[section] as Category).name
    return Product.objectsWhere("productCategory.name == '\(categoryName)'")
}


override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        // Delete the row from the data source
        var realm = RLMRealm.defaultRealm()
        let productsForSection = objectsForSection(UInt(indexPath.section)) // This returns an RLMResults
        let product = productsForSection[UInt(indexPath.row)] as Product
        realm.beginWriteTransaction()
        realm.deleteObject(product)
        realm.commitWriteTransaction()
        tableView.deleteRowsAtIndexPaths([indexPath.row], withRowAnimation: .Fade)
    } else if editingStyle == .Insert {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }    
}

当我滑动并按下删除时,它崩溃了。我做错了什么?

提前致谢!

最佳答案

你有一行内容是:

tableView.deleteRowsAtIndexPaths([indexPath.row], withRowAnimation: .Fade)

它传递一个带有行号的数组,而不是 NSIndexPath

我相信你的意思是:

tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

关于ios - -[__NSCFNumber 行] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26992731/

相关文章:

ios - 我可以将现有的 Popover 用于 UIImagePickerController 吗?

swift - 从 View 之外的函数访问@StateObject

swift - Realm ;使将来迁移所需的可选属性

ios - viewController.view 未添加到父 View Controller 内的自定义 View

ios - HTML5 视频无法在 native iOS 电子邮件客户端中播放 (2015)

iphone - 更改 UIPickerView 中两个不同组件中的行

ios - 面对新的iOS室内定位能力

javascript - Realm.open 与新 Realm

swift - 如何更新版本来修复此错误? : 'Realm version is higher than the current version provided to ` setSchemaVersion:withMigrationBlock :`'

ios - 以编程方式从底部裁剪图像