![](/img/trans.png)
[英]'-[__NSCFNumber row]: unrecognized selector sent to instance 0xb416910'
[英]-[__NSCFNumber row]: unrecognized selector sent to instance
我已经检查了其他答案,但它们似乎无法正确回答我的问题。 如果有明显的我没见过,请在我的评论中注明:)
我所拥有的是一个具有Realm数据库作为数据源的tableView。 我希望能够从源中删除被删除的单元格。
这是代码:
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
}
}
当我进行滑动并按Delete时,它会崩溃。 我究竟做错了什么?
提前致谢!
您有一行显示:
tableView.deleteRowsAtIndexPaths([indexPath.row], withRowAnimation: .Fade)
这将传递具有行号的数组,而不是NSIndexPath
。
我相信你的意思是:
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.