单元格下移到右侧单元格滑动删除UITableView
粉红色被赋予单元格的内容视图。单元格下移到右侧单元格滑动删除UITableView
虽然通过刷卡删除电池使用委托commitEditingStyle
删除仅删除删除单元格下方的单元之后被转移到右侧
我没有得到任何有关的想法那为细胞留下了余量。 滚动并返回到放错位置的单元格时,布局正确并且该边距被移除。
我在Xcode 8.0中使用了Swift。
下面是代码:
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
// handle delete (by removing the data from your array and updating the tableview)
let date = dateKeys[indexPath.section]
var notificationObject = dataSection[date] as! [Notification]
let deleteNotificationId = notificationObject[indexPath.row].notifId
for notifObject in self.notificationArray {
if notifObject.notifId == deleteNotificationId {
if let index = self.notificationArray.indexOf(notifObject) {
self.notificationArray.removeAtIndex(index)
self.dataSection = self.categorizeNotification(self.notificationArray)
self.dateKeys = self.sortArrayDate()
self.notificationTable.reloadData()
break
}
}
}
}
}
你应该写为删除此行代码表视图:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// the cells you would like the actions to appear needs to be editable
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
if editingStyle == .delete
{
showsArray.remove(at: indexPath.row)
tableView.reloadData()
}
}
是的,它已经在我的代码中。删除操作是通过从数组中删除并重新加载从数组填充的数据是正确的,但删除的单元格正下方的单元格移动到右侧。 然后在滚动表格之后,当该单元格再次出现时,它会固定在正确的位置。 –
请勿重新载入您的表格。只需从数组中删除对象。 –
抱歉它没有工作... –
Occour同样的问题。
override func layoutSubviews() {
super.layoutSubviews()
if self.editingStyle != .delete && self.frame.origin.x > 0{
var originFrame = self.frame
originFrame.origin.x = 0
self.frame = originFrame
}
}
设置的UITableViewCell frame.origin.x
零避免它。
我在删除“commitEditingStyle”函数中的数组中的项后重新加载表。 –
在这里发布您的commitEditingStyle代码。 – KAR
在此处提及带有屏幕截图的代码。 – KKRocks