2016-08-23 105 views
-3

我想取消選擇先前選擇的行再次選擇。我只能取消選中該行點擊其他行,但我想再次取消選擇此點擊。我怎樣才能做到這一點?如何取消選擇在目標c中選擇的行?

這是我的代碼:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
[self updateTableView]; 
} 

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
[self updateTableView]; 
} 


- (void)updateTableView 
{ 
[self.tableView beginUpdates]; 
[self.tableView endUpdates]; 
} 

謝謝!

+0

請在發佈問題之前檢查是否存在相關的問題。 http://stackoverflow.com/questions/3968037/how-to-deselect-a-selected-uitableview-cell –

回答

0

在tableviews中有一個deselectRowAtIndexPath方法。使用該方法傳遞您的索引路徑。

0

使用屬性跟蹤選定的索引路徑。在tableView:didSelectRowAtIndexPath:內將您存儲的索引路徑與委託方法中提供的索引路徑進行比較。如果它們相同,則表示該行已被選中。撥打電話deselectRowAtIndexPath:animated:取消選擇它並將存儲的索引路徑設置爲零。否則,將存儲的索引路徑更新爲委託方法中提供的索引路徑。

相關問題