iOS11 拖动行为在 UITableView 中不起作用



我在开发拖放iOS11功能以允许在应用程序之间发送和接收数据时遇到问题。

在视图控制器的 tableView 中,dragDelegatedropDelegateviewDidLoad分配给视图控制器本身,我实现了

- (NSArray<UIDragItem *> *)tableView:(UITableView *)tableView itemsForBeginningDragSession:(id<UIDragSession>)session atIndexPath:(NSIndexPath *)indexPath方法,但从未调用过。

拖放行为工作正常,表格视图可以使用其他应用(如"照片"或"备忘录"(中的项目。但是当我点击表格视图行几秒钟时,没有任何反应。不会发生提升动画,也不会触发拖动委托。

有什么想法吗?我错过了什么需要的东西吗?

在iPhone上,除了设置dragDelegate外,还必须将UITableView上的dragInteractionEnabled设置为true。在 iPad 上,此属性默认设置为 true。

请尝试以下委托方法来重新排序单元格。

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}

在项目中实现以下 UITableView 数据源方法。

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
[dataArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
[self.tableView reloadData];
}

相关内容

最新更新