iOS自定义表格视图单元格在编辑模式下调整大小 [英] iOS custom table view cell resize in edit mode

查看:267
本文介绍了iOS自定义表格视图单元格在编辑模式下调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑 UITableView 时,圆形红色按钮和删除按钮重叠自定义单元格。

When editing the UITableView the round red button and the delete button overlaps the custom cell.

怎么能我们调整自定义单元格的大小,为红色圆形按钮和删除按钮留出空间。

How can we resize the custom cell to leave space for the red round button and the delete button.

推荐答案

使用此代码,您可以执行不同的任务取决于如何以及编辑单元格的阶段。我对代码进行了大量评论,因为我花了这么长时间来自己解决这个问题。 (变得混乱)

With this code, you can perform different tasks depending on how, and what stage of editing the cell is in. I've commented the code heavily because it took me so long to figure this out on my own. (gets confusing)

  - (void)willTransitionToState:(UITableViewCellStateMask)state {

        [super willTransitionToState:state];

        if (state == UITableViewCellStateDefaultMask) {

            NSLog(@"Default");
            // When the cell returns to normal (not editing)
            // Do something...

        } else if ((state & UITableViewCellStateShowingEditControlMask) && (state & UITableViewCellStateShowingDeleteConfirmationMask)) {

            NSLog(@"Edit Control + Delete Button");
            // When the cell goes from Showing-the-Edit-Control (-) to Showing-the-Edit-Control (-) AND the Delete Button [Delete]
            // !!! It's important to have this BEFORE just showing the Edit Control because the edit control applies to both cases.!!!
            // Do something...

        } else if (state & UITableViewCellStateShowingEditControlMask) {

            NSLog(@"Edit Control Only");
            // When the cell goes into edit mode and Shows-the-Edit-Control (-)
            // Do something...

        } else if (state == UITableViewCellStateShowingDeleteConfirmationMask) {

            NSLog(@"Swipe to Delete [Delete] button only");
            // When the user swipes a row to delete without using the edit button.
            // Do something...
        }
    }

你说你添加了自定义标签,但没有,我在使用tableviews之前也做过同样的事情。我通常喜欢使用动画块隐藏重叠的视图,如:

You said you added custom labels and what not, and I've done the same before while using tableviews. I usually prefer to "hide" the views that are getting overlapped using an animation block like:

[UIView animateWithDuration:0.3

                        animations:^ {
                            self.myTableCellSubview.alpha = 0.0f;
                        }
        ];

在上面的每个if语句中,并将alpha从1.0f更改为0.0f,具体取决于状态。

inside each of the if statements above, and changing the alpha from 1.0f to 0.0f depending on the state.

对于一般的缩进,在属性检查器中,确保选中编辑时缩进,您也可以通过编程方式设置:

As for the indentation in general, in the attributes inspector, make sure "Indent While Editing" is checked, which you can also set programmatically with:

cell.shouldIndentWhileEditing = YES;

如果这不起作用,您可能会在自动调整过程中出现一些奇怪之处。在故事板或xib中,选择需要缩进的单元格的子视图,然后转到大小检查器(标尺选项卡)。如果子视图需要从左侧缩进(--->),请确保它固定在左侧:

If that doesn't work, you may have some quirkyness going on in your autosizing. In your storyboard, or xib, select the subview of your cell that needs to be indented and go to the Size inspector (ruler tab). If the subview needs to be indented from the left ( ---> ), make sure it's pinned to the left:

如果子视图需要从右侧缩进(< - - ),确保它固定在右边:

If the subview needs to be indented from the right ( <--- ), make sure it's pinned to the right:

希望这会有所帮助!

这篇关于iOS自定义表格视图单元格在编辑模式下调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆