我正在跟踪this official documentation by Apple。我正在尝试在我的UITableView
上实现拖放功能。问题是,行不会移动。如你所见,它们总是反弹:
这是我的代码:
func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)
{
// This gets called, when I reach a UITableViewCell above or below
// the one UITableViewCell I'm dragging around. This is the part
// where it always snaps back I think.
}
func tableView(tableView: UITableView, targetIndexPathForMoveFromRowAtIndexPath sourceIndexPath: NSIndexPath, toProposedIndexPath proposedDestinationIndexPath: NSIndexPath) -> NSIndexPath
{
return proposedDestinationIndexPath
}
我正在使用DZNEmptyDataSet库,不太确定这是否干扰了
UITableView
的原始功能。我错过了什么?
编辑:我在我的项目中创建了一个新的
ViewController
,其行为完全相同。但是,如果我试图在一个新项目中实现此功能,它只是按预期工作。 最佳答案
“问题”是另一个库MMDrawerController。在我的TableView
上启用编辑时,我必须禁用MMDrawerController
手势。这里的代码修复了我的问题:
///
/// Enable edit mode
///
func editEntries()
{
self.disableDrawerFunctionality()
self.tableView.setEditing(true, animated: true)
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Fertig", style: .Plain, target: self, action: "finishedEditing:")
}
func finishedEditing(sender: AnyObject)
{
self.tableView.setEditing(false, animated: true)
self.navigationItem.rightBarButtonItem = self.barButtonItemEdit
self.enableDrawerFunctionality()
}
// MARK: - Toggle Drawer functionalities
///
/// While in TableView edit mode: Be sure to disable the MMDrawer gestures, since the gestures will colide
/// with gestures of the TableView
///
func enableDrawerFunctionality()
{
mm_drawerController.openDrawerGestureModeMask = .PanningCenterView
mm_drawerController.closeDrawerGestureModeMask = .PanningDrawerView | .PanningCenterView
}
///
/// When leaving TableView edit mode: Re-enable the MMDrawer gestures after finishing editting the TableView
///
func disableDrawerFunctionality()
{
mm_drawerController.openDrawerGestureModeMask = .None
mm_drawerController.closeDrawerGestureModeMask = .None
}
下面是他们的自述部分,引起了我的注意:
你可以自由设定你想要的开和关的组合。请注意,这些手势可能会影响发送到子视图控制器的触摸,因此请确保在应用程序中正确使用这些手势。例如,如果MKMapView是中心视图控制器,则不希望设置MMOpenDrawerGestureModePanningCenterView,因为它将截获用于在地图上移动的平移。