簡體   English   中英

iOS11 拖動行為在 UITableView 中不起作用

[英]iOS11 Drag behavior not working in UITableView

我在開發拖放 iOS11 功能以允許在應用程序之間發送和接收數據時遇到問題。

在視圖控制器的 tableView 中,將viewDidLoad上的dragDelegatedropDelegate分配給視圖控制器本身,我實現了

- (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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM