gpt4 book ai didi

ios - UITableViewCell.accessoryView 将在 iOS 7 中消失

转载 作者:行者123 更新时间:2023-11-29 12:56:49 24 4
gpt4 key购买 nike

我将一些自定义 View 分配给 UITableViewCell.accessoryView,但是如果我疯狂滚动 tableView,一些 accessoryView 会在 iOS 7 中消失,如果我触摸单元格,它是 accessoryView 可以出现,我不知道为什么,因为它在 iOS 6 中是正确的。这是我的代码,有人可以帮助我吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [NSString stringWithFormat:@"CELL %d", (int)indexPath.row+1];

NSDictionary * dict = [_dataSource objectAtIndex:indexPath.row];
if ([dict objectForKey:@"switch"])
{
cell.accessoryView = [dict objectForKey:@"switch"];
}
else
{
cell.accessoryView = nil;
}

return cell;
}

最佳答案

当我们在 TableView 中使用 ReusableCellWithIdentifier 时,它会重用表中的单元格,您设置 cell.accessoryView = nil; 它会删除 TableView 中所有具有相同 CellIdentifier 试试这个代码,它解决了你的问题:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NSDictionary * dict = [_dataSource objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryView = [dict objectForKey:@"switch"];
}
cell.textLabel.text = [NSString stringWithFormat:@"CELL %d", (int)indexPath.row+1];

if ([dict objectForKey:@"switch"])
{
cell.accessoryView.hidden=NO;
}
else
{
cell.accessoryView.hidden=YES;
}
return cell;
}

关于ios - UITableViewCell.accessoryView 将在 iOS 7 中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20876059/

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