gpt4 book ai didi

ios - 如何在 TableView 中简单更改复选标记?

转载 作者:行者123 更新时间:2023-11-28 22:36:12 24 4
gpt4 key购买 nike

在我的应用程序中,在 Storyboard 中,我有一个包含很多 TableView 单元格的屏幕。

例如,在其中的前两个中,当用户触摸其中一个(进行选择)时,我需要移动复选标记。

enter image description here

是否有一种简单的方法可以做到这一点,例如,像 socket 连接?或者怎么做?

谢谢。

最佳答案

查看有关 managing selections in UITableView 的 Apple 文档.基本上,您将在 TableView 的 didSelectRowAtIndexPath 方法中协调先前选定的单元格(删除复选标记附件)和当前选定的单元格(添加复选标记附件)的附属 View 。

这是一个粗略的实现,假设您有一组可用的 taskTypes,并且选择了 currentTaskType 的属性。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];

NSInteger taskTypeIndex = [taskTypes indexOfObject:[self currentTaskType]];

if ( taskTypeIndex == [indexPath row] )
{
return;
}

NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:taskTypeIndex inSection:0];
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];

if ( [newCell accessoryType] == UITableViewCellAccessoryNone )
{
[newCell setAccessoryType:UITableViewCellAccessoryCheckmark];
[self setCurrentTaskType:[taskTypes objectAtIndex:[indexPath row]]];
}

if ( [oldCell accessoryType] == UITableViewCellAccessoryCheckmark )
{
[oldCell setAccessoryType:UITableViewCellAccessoryNone];
}
}

关于ios - 如何在 TableView 中简单更改复选标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15911510/

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