UITableViewCell附件视图未显示在iOS6中,但显示在iOS7中

UITableViewCell附件视图未显示在iOS6中,但显示在iOS7中,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个UITableView,因此我必须在单元格的选择上显示复选标记,并在取消选择时显示详细信息(如果再次选择行)。我的代码如下: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.a

我有一个
UITableView
,因此我必须在单元格的选择上显示复选标记,并在取消选择时显示详细信息(如果再次选择行)。我的代码如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if (cell.accessoryType == UITableViewCellAccessoryDisclosureIndicator || cell.accessoryType == UITableViewCellAccessoryDetailButton || cell.accessoryType == UITableViewCellAccessoryDetailDisclosureButton)
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;

    }
    else if(cell.accessoryType == UITableViewCellAccessoryCheckmark)
    {
        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
            cell.accessoryType = hasGroupID ? UITableViewCellAccessoryDetailButton : UITableViewCellAccessoryDisclosureIndicator;
        else
            cell.accessoryType = hasGroupID ? UITableViewCellAccessoryDetailDisclosureButton : UITableViewCellAccessoryDisclosureIndicator;

    }

    [self.tableView reloadData];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
这里的问题是,它在iOS 7设备上工作得很好,但在iOS 6上,附件视图没有出现

需要一些关于这里可能存在什么问题以及需要做什么来解决它的指导


谢谢。

重新加载的数据导致UITableView将完全重新绘制。didSelectRowAtIndexPath中的附件集通过在数据源处理程序中新调用cellForRowAtIndexPath清除。

您不能依赖于直接修改
单元格

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    checkedRows[indexPath.row] = !checkedRows[indexPath.row];
    [tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"somecell"];

    if(!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    cell.accessoryType = checkedRows[indexPath.row] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;

    return cell;
}

而是修改基础数据,然后调用
[self.tableView reloadData]
。在
单元格中,根据该索引路径的数据,相应地设置附件。

didSelectRowAtIndexPath:
中尝试此操作

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if(cell.accessoryType == UITableViewCellAccessoryCheckmark)
    {
           if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
               cell.accessoryType = hasGroupID ? UITableViewCellAccessoryDetailButton : UITableViewCellAccessoryDisclosureIndicator;
           else
               cell.accessoryType = hasGroupID ? UITableViewCellAccessoryDetailDisclosureButton : UITableViewCellAccessoryDisclosureIndicator;

    } else if (cell.accessoryType != UITableViewCellAccessoryNone) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }

    [self.tableView reloadData];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

cellforrowatinexpath
方法中检查您的代码。我认为它第一次是正确的,但在选择之后,它会使用复选标记