【发布时间】:2014-06-13 00:43:10
【问题描述】:
您好,我目前正在使用核心数据框架开发基于表格视图的 iPhone 应用程序。到目前为止进展顺利,但我在一个非常简单的问题上苦苦挣扎。我刚刚学习了 Swift,我正在尝试自学并开发一些有用的东西。我已经成功地用核心数据数据库中的数据填充了一个表视图。但是,我正在努力从数据源和表视图中删除该行。
这是我目前正在尝试的代码:
override func tableView(tableView: UITableView?, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath?) {
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
if editingStyle == .Delete {
println("Delete")
// Delete the row from the data source
context.deleteObject(myData.objectAtIndex(indexPath.row) as NSManagedObject)
tableView.deleteRowsAtIndexPaths([indexPath], 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
}
}
错误截图:
有什么建议吗?
【问题讨论】:
-
您需要解开
indexPath?和tableView?变量 - 重复 - stackoverflow.com/questions/24040405/… -
感谢您的回答。
标签: ios xcode uitableview swift