如何使用 swift 2.2 从表视图中删除一行
How to delete a row from tableview using swift 2.2
我正在使用 swift 在我的应用程序中开发一个应用程序 我正在使用 table 视图来添加联系人 现在我想从 table 视图中删除一行 我已经检查了其他堆栈溢出答案,但对我来说没有任何效果
我的 table 视图控制器中的代码:
func
tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
{
return true
}
functableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if (editingStyle == UITableViewCellEditingStyle.Delete)
{
dataArray.removeAtIndex(indexPath.row)
self.FirstTableView.reloadData()
}
}
这个对我没有帮助,单元格甚至没有移动和显示删除按钮
注意:1.am 使用左侧导航抽屉所以我不能向左滑动
2.I 只想在右侧滑动
3.am 不对任何内容添加任何约束 我使用大小 类 和自动布局
你检查一下你定义的这个委托方法(我想你错过了这个)
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.Delete
}
并在单元格提交样式中删除数据,如下所示:
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext!
context.deleteObject(dataarray[indexPath.row] as NSManagedObject)
dataarray.removeAtIndex(indexPath.row)
context.save(nil)
self.FirstTableView.reloadData()
我正在使用 swift 在我的应用程序中开发一个应用程序 我正在使用 table 视图来添加联系人 现在我想从 table 视图中删除一行 我已经检查了其他堆栈溢出答案,但对我来说没有任何效果
我的 table 视图控制器中的代码:
func
tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
{
return true
}
functableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if (editingStyle == UITableViewCellEditingStyle.Delete)
{
dataArray.removeAtIndex(indexPath.row)
self.FirstTableView.reloadData()
}
}
这个对我没有帮助,单元格甚至没有移动和显示删除按钮
注意:1.am 使用左侧导航抽屉所以我不能向左滑动
2.I 只想在右侧滑动
3.am 不对任何内容添加任何约束 我使用大小 类 和自动布局
你检查一下你定义的这个委托方法(我想你错过了这个)
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.Delete
}
并在单元格提交样式中删除数据,如下所示:
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext!
context.deleteObject(dataarray[indexPath.row] as NSManagedObject)
dataarray.removeAtIndex(indexPath.row)
context.save(nil)
self.FirstTableView.reloadData()