gpt4 book ai didi

ios - 滚动 tableview 会删除 uitableview 单元格中的复选标记

转载 作者:行者123 更新时间:2023-11-29 04:08:35 25 4
gpt4 key购买 nike

我正在使用 tableview 并且正在对 uitableview 进行多次检查。一切都很完美,我'获得了正确的值,但是当我滚动 TableView 时,它丢失了复选标记图像(使用默认复选标记,没有自定义图像),但所选值保留在数组中...

滚动表格 View 会删除复选标记图像。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate *app= (AppDelegate *)[[UIApplication sharedApplication]delegate];

if([_tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){

NSLog(@"yes");

[placesvisitedarray removeObject:[app.nameArray objectAtIndex:indexPath.row]];


[_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;

}
else
{
NSLog(@"no");

[_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;

[placesvisitedarray addObject:[app.nameArray objectAtIndex:indexPath.row]];

}
// [_tableView reloadData];

}

最佳答案

复选标记已被删除,因为当您滚动表格 View 时,将调用 cellForRowAtIndexPath: 并重新创建单元格。

您可以编写一个方法来检查数组中是否存在某个值:

- (BOOL)stringExistsInPlacesVisited:(NSString *)stringToMatch {
for (NSString string in placesvisitedarray) {
if ([string isEqualTo:stringToMatch])
return YES;
}
return NO;
}

然后在cellForRowAtIndexPath:中,您必须检查placesvisitedarray并插入/删除复选标记。

if ([stringExistsInPlacesVisited:[app.nameArray objectAtIndex:indexPath.row])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;

代码未经测试,因此可能无法工作,但至少它会让您了解如何继续。

关于ios - 滚动 tableview 会删除 uitableview 单元格中的复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14797316/

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