1

にいくつかのカスタム ビューを割り当てます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;
}
4

1 に答える 1

1

テーブル ビューで ReusableCellWithIdentifier を使用すると、テーブル内のセルが再利用されます。cell.accessoryView = nil;を設定します。同じ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;
}
于 2014-01-02T04:39:17.597 に答える