gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 05:32:49 25 4
gpt4 key购买 nike

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

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com