![](/img/trans.png)
[英]How check one cell of tableView and uncheck rest of the cells in the section in swift
[英]how to uncheck all cells on tableview in ios
我有一個tableview,當用戶選擇單元格時,它將accessorytype
設置為UITableViewCellAccessoryCheckmark
。
現在,當我導航到上一個屏幕時,然后轉到此表視圖,我的單元格保持選中狀態。
有沒有辦法取消所有選擇? 我想基本上將它們全部設置為UITableViewCellAccessoryNone
。
我嘗試使用reloadData
,當視圖出現時,但這似乎不會觸發cellForRowAtIndexPath
(這是我的邏輯是設置單元格的accessorytype
的地方)
我認為這可以做您想要的。 我假設您想取消選中所有單元格作為對tableView:didSelectRowAtIndexPath:的響應,但是您可以在以下任何位置插入此代碼:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Uncheck any visible, checked cells.
NSArray *visibleCells = [tableView visibleCells];
for (UITableViewCell *cell in visibleCells) {
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
// Now do whatever else you want in response to a row being selected.
}
您應該在tableView:willDisplayCell:forRowAtIndexPath:
而不是cellForRowAtIndexPath
設置附件類型,以便在顯示時(而不是僅在創建時)更新附件類型。
將會出現一個名為clearsselectiononview的表視圖方法,您可能已經意外覆蓋了該方法。 默認行為應為“是”。 在UITab上查看Apple的文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.