如何删除">"在表中查看单元格并删除单元格,因为每个索引都在不同的indexPath中?

时间:2014-05-22 15:25:53

标签: ios objective-c uitableview

我遇到了这个问题。我所做的是indexPath.row % 2 == 1中的每个单元格我想将其设置为空白,因此可能存在余量。但现在它看起来像这样:

enter image description here

我想删除“>”在作为边际的单元格中。按下时如何删除并删除突出显示的内容?按下时会变为灰色。

如何删除具有此逻辑的单元格,因为每一行都是奇数,但实际对象仍在其正确的索引中。

这是我的代码:

if (indexPath.row % 2 == 1) {
    UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2];

    if (cell2 == nil) {
        cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELL_ID2];
        [cell2.contentView setAlpha:0];
        cell2.selectionStyle = UITableViewCellSelectionStyleNone;
        cell2.userInteractionEnabled = NO;

    }
    return cell2;
}

3 个答案:

答案 0 :(得分:1)

只需设置cell2.accessoryType = UITableViewCellAccessoryNone;

即可

答案 1 :(得分:0)

您需要将accessaryType设置为UITableViewCellAccessoryNone

cell2.accessoryType = UITableViewCellAcessoryNone;

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITableViewCellAccessoryType

答案 2 :(得分:0)

你非常接近:

if (indexPath.row % 2 == 1) {
    UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2];

    if (cell2 == nil) {
        cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELL_ID2];
    }

    cell2.selectionStyle = UITableViewCellSelectionStyleNone;
    cell2.accessoryType = UITableViewCellAccessoryNone;

    return cell2;
}

您的单元格配置(如果单元格为零)应该包含您所需的最小值,因为单元格会被重用(dequeueReusableCellWithIdentifier:)。因此,您需要在重用时配置单元格的每个独立部分。因此,您需要为indexPath的该行设置所需的属性。