[英]didDeselectRowAtIndexPath isn't called
我在UITableView
實現了didDeselectRowAtIndexPath
方法,其中包括多個選擇。
出於某種原因, didDeselectRowAtIndexPath
不會調用didDeselectRowAtIndexPath
。 有什么建議么? (我沒有意外拼錯didSelectRowAtIndexPath
)。
謝謝!
有關細胞選擇的一些注意事項:
didDeselectRowAtIndexPath
僅在單選UITableView
調用,如果用戶單擊與已選擇的單元格不同的單元格。 didSelectRowAtIndexPath
來選擇新行,調用didDeselectRowAtIndexPath
來取消選擇前一行 UITableView
,未取消選擇上一行,因此在didSelectRowAtIndexPath
處理取消選擇 你可以使用你實現的委托方法獲取單元格,並在檢查它的選擇后修改它,如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell.selected) {
// ... Uncheck
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
我目前使用帶有多個選擇的tableView,並且didDeselectRowAtIndexPath方法正在調用我(不同於上面答案中的第三個項目符號中所述)。
我注意到“預選”的單元格沒有正確調用didDeselectRowAtIndexPath,除非我做了三件事:
示例代碼:
if productsReceived!.rangeOfString(cell.productName.text!) != nil {
cell.accessoryType = .Checkmark
tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.None)
cell.selected = true
}
我希望這可以幫助那些嘗試使用預選單元格實現多重選擇的人。
如果我沒弄錯的話, UITableView
沒有用於取消選擇單元格的內置方法。 我相信你需要調用deselectRowAtIndexPath:
以便調用didDeselectRowAtIndexPath
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.