2012-10-04 33 views

回答

0
- (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 
} 
+0

問題是,我仍然無法更新單元格的背景圖像,*當用戶正在移動它時,使用此。我試圖解決這個問題:http://stackoverflow.com/questions/12717566/custom-grouped-table-view-cell-updates-background-image-in-relation-to-position – James

+0

使用委託!從委託中複製://在用戶更改選擇之前調用。返回一個新的indexPath或nil來更改建議的選擇。 (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath; – YoYoHu

+0

你是正確的獲取索引路徑。我仍然無法重繪單元格背景,但我想這是一個單獨的問題。感謝你的回答。 – James

0

讓代表爲您處理這個問題。那就是爲什麼它在那裏! - 的tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:

+0

我嘗試了這個委託方法,但無法使用它來更新單元格背景的分組表視圖。你可以顯示我將如何配置單元格移動與'-tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:'? – James

相關問題