gpt4 book ai didi

ios - 如何在单元格选择/取消选择时正确切换 UITableViewCell accessoryType?

转载 作者:可可西里 更新时间:2023-11-01 05:02:33 24 4
gpt4 key购买 nike

我正在尝试在选择/取消选择表格单元格时切换 accesoryType...行为应该是:点击 -> 将 accessoryType 设置为 UITableViewCellAccessoryCheckmark -> 点击再次单元格 -> 回滚到 UITableViewCellAccessoryNone 类型。我的 Controller 中的实现如下:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setAccessoryType:UITableViewCellAccessoryNone];
}

...无论如何,一旦样式配置为UITableViewCellAccessoryCheckmark,我就无法将其恢复为UITableViewCellAccessoryNone!我也试过打电话:

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];

但没有删除复选标记...我该怎么办?

编辑:实现没问题,问题出在自定义 UITableViewCell 子类中...抱歉:P

最佳答案

如果这是你想要的,试试这个

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}

关于ios - 如何在单元格选择/取消选择时正确切换 UITableViewCell accessoryType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8870552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com