如何在tableview编辑时显示该行?

时间:2012-03-16 06:56:16

标签: iphone tableview

我有一个问题,如何在tableview编辑时显示复选标记和移动之间的界限。与下图中的相同。

enter image description here

解释过程,否则请将示例代码发送给我。

提前致谢。

6 个答案:

答案 0 :(得分:5)

看看这个:

声明BOOL checkMark;在.h 检查它的价值。

// This all code in Cell For Row At IndexPath :

for (UIView *ObView in [cell.contentView subviews])

{

    [ObView removeFromSuperview];
}

if(checkMark == YES)  // you can check here by imdexPath.row.

{
     UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10,5,150,30)];
    lbl.text = @"";
    [cell.contentView addSubview:lbl];

    UIImageView *CheckImage = [[UIImageView alloc]initWithFrame:CGRectMake(160,5,20,20)];
    CheckImage.image = [UIImage imageNamed:@""];
    [cell.contentView addSubview:CheckImage];

    UIImageView *BarImage = [[UIImageView alloc]initWithFrame:CGRectMake(185,5,0.5,30)];
    BarImage.image = [UIImage imageNamed:@""];
    [cell.contentView addSubview:BarImage];

    UIImageView *tblImage = [[UIImageView alloc]initWithFrame:CGRectMake(160,5,20,20)];
    tblImage.image = [UIImage imageNamed:@""];
    [cell.contentView addSubview:tblImage];
}
else
{
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10,5,150,30)];
    lbl.text = @"";
    [cell.contentView addSubview:lbl];

    UIImageView *tblImage = [[UIImageView alloc]initWithFrame:CGRectMake(160,5,20,20)];
    tblImage.image = [UIImage imageNamed:@""];
    [cell.contentView addSubview:tblImage];
}

注意:帧是临时的。

答案 1 :(得分:1)

所以你基本上有一个tableView并且你想要添加那个图像“|”在编辑时tableViewCell

我认为你的tableView已经有editingEnabled,你需要实现

- (void)setEditing:(BOOL)editing animated:(BOOL)animate

  {

   if (editing) {
             // Configure self.tableView and individual cells and add the "|" as a subView. 
             // It will all be tricky, and you should be able to logically place the vertical bar
             // But whatever you want to be in your EDIT mode, you will have to configure it here.
    } else {
          // Re-configure and implement the 'correct' cells back to normal tableView
    }

 }

答案 2 :(得分:0)

创建一个宽度为1px,背景为灰色的UIView,并将其添加到复选标记右侧应该没问题。

答案 3 :(得分:0)

如果您编辑选项是图像,那么您可以执行如下所示的代码以显示一行。

<强>步骤

1]首先导入QuartzCore / QuartzCore.h

2]设置编辑图像的边框宽度和边框颜色属性。

[editImageView.layer setBorderWidth:2.0];

[editImageView.layer setBorderColor:[[UIColor grayColor] CGColor]];

//If you putting a button for edit then also you can set the same. Just replace the editImageView with your editButton

希望你得到你想要的确切!:)

答案 4 :(得分:0)

在表格单元格中取uiimageview并将其宽度设置为1.根据tablename.cell.height设置高度。

它肯定会解决你的问题

答案 5 :(得分:0)

您可以自定义您的tableview单元格。只需在创建单元格时添加子视图并隐藏它,直到单击编辑按钮。