当编辑UITableView
时,圆形红色按钮和删除按钮会重叠在自定义单元格上。
我们如何调整自定义单元格的大小,以留出空间给圆形红色按钮和删除按钮。
使用此代码,您可以根据单元格的编辑方式和编辑阶段执行不同的任务。我已经添加了大量注释,因为我自己花了很长时间才弄明白这个过程。(有点复杂)
- (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时也做过同样的事情。通常我喜欢使用动画块来“隐藏”被重叠的视图,代码如下:
[UIView animateWithDuration:0.3
animations:^ {
self.myTableCellSubview.alpha = 0.0f;
}
];
在上面的if语句中,根据状态将alpha从1.0f更改为0.0f。
至于缩进,可以在属性检查器中确保“编辑时缩进”被勾选,您也可以通过编程方式设置:
cell.shouldIndentWhileEditing = YES;
我认为您可以覆盖其中一个方法并调整自定义单元格的大小。不过,根据问题,我不确定这是否完全符合您的要求。
- (void)willTransitionToState:(UITableViewCellStateMask)state
- (void)didTransitionToState:(UITableViewCellStateMask)state