當表格視圖處於編輯模式並且用戶正在移動單元格時。目前正在移動的單元格的索引路徑是什麼?剩餘單元格的索引路徑如何受到影響?用戶當前正在重新排列(移動)的表格視圖單元格的索引路徑是什麼?
(實際上,我試圖瞭解這一點是爲了解決this problem。)
任何幫助表示讚賞。謝謝!
當表格視圖處於編輯模式並且用戶正在移動單元格時。目前正在移動的單元格的索引路徑是什麼?剩餘單元格的索引路徑如何受到影響?用戶當前正在重新排列(移動)的表格視圖單元格的索引路徑是什麼?
(實際上,我試圖瞭解這一點是爲了解決this problem。)
任何幫助表示讚賞。謝謝!
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath: (NSIndexPath *)proposedDestinationIndexPath
{
if (proposedDestinationIndexPath.section != sourceIndexPath.section)
{
return sourceIndexPath;
}
return proposedDestinationIndexPath;
}
不要忘記做你的tableView另一個檢查:moveRowAtIndexPath:toIndexPath:數據源方法如下圖所示,你不希望運行你的應用程序邏輯當目標類似於來源。
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
if(sourceIndexPath == destinationIndexPath)
{
return;
}
//application logic
}
讓代表爲您處理這個問題。那就是爲什麼它在那裏! - 的tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
我嘗試了這個委託方法,但無法使用它來更新單元格背景的分組表視圖。你可以顯示我將如何配置單元格移動與'-tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:'? – James
問題是,我仍然無法更新單元格的背景圖像,*當用戶正在移動它時,使用此。我試圖解決這個問題:http://stackoverflow.com/questions/12717566/custom-grouped-table-view-cell-updates-background-image-in-relation-to-position – James
使用委託!從委託中複製://在用戶更改選擇之前調用。返回一個新的indexPath或nil來更改建議的選擇。 (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath; – YoYoHu
你是正確的獲取索引路徑。我仍然無法重繪單元格背景,但我想這是一個單獨的問題。感謝你的回答。 – James