本文介紹了UITableView 一次只勾選一行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
使用此代碼,我可以檢查表中的多行.
With this code, I can check multiple rows in a table.
但我想要的是一次只檢查一行.這是我的代碼:
But what I want is to only have one row checked at a time. Here's my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *theCell = [tableView cellForRowAtIndexPath:indexPath];
if (theCell.accessoryType == UITableViewCellAccessoryNone) {
theCell.accessoryType = UITableViewCellAccessoryCheckmark;
} else if (theCell.accessoryType == UITableViewCellAccessoryCheckmark) {
theCell.accessoryType = UITableViewCellAccessoryNone;
}
}
如果用戶選擇了不同的行,那么我希望舊行簡單地自動取消選中.不知道該怎么做.
If a user selects a different row, then I want the old row to simply automatically uncheck. Don't know how to do that.
推薦答案
最好的方法是在cellForRowAtIndexPath
中設置附件類型.
The best way is to set the accessory type in cellForRowAtIndexPath
.
使用didSelectRowAtIndexPath
只記錄應該選擇哪條路徑,然后調用reloadData
.
Use didSelectRowAtIndexPath
to only record which path should be selected and then call reloadData
.
這篇關于UITableView 一次只勾選一行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!