UItableViewCell滑动删除时,调整cell的位置大小是否显示等。
CustomTableViewCell为UITableViewCell的子类,在实现文件中重写willTransitionToState方法。
willTransitionToState是在cell改变显示状态的时候调用,有三种状态:
typedef NS_OPTIONS(NSUInteger, UITableViewCellStateMask) {
UITableViewCellStateDefaultMask = 0, //普通状态
UITableViewCellStateShowingEditControlMask = 1 << 0, //编辑状态
UITableViewCellStateShowingDeleteConfirmationMask = 1 << 1 //删除状态
};
具体实现方法:
- (void) willTransitionToState:(UITableViewCellStateMask)state{[super willTransitionToState:state];//UITableViewCellStateShowingDeleteConfirmationMaskif ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {for (UIView *subview in self.subviews) {if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {//this is delete button}if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellContentView"]) {//this is contentViewfor (UIView *sub in subview.subviews) {if ([NSStringFromClass([sub class]) isEqualToString:@"UILabel"]) {UILabel *subLabel = (UILabel *)sub;if (subLabel.tag == 8) {subLabel.hidden = YES;}}if ([NSStringFromClass([sub class]) isEqualToString:@"UIImageView"]) {UILabel *subImageView = (UILabel *)sub;if (subImageView.tag == 11) {subImageView.hidden = YES;}}}}}}//UITableViewCellStateDefaultMaskif ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateDefaultMask){for (UIView *subview in self.subviews) {if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {//this is delete button}if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellContentView"]) {//this is contentViewfor (UIView *sub in subview.subviews) {if ([NSStringFromClass([sub class]) isEqualToString:@"UILabel"]) {UILabel *subLabel = (UILabel *)sub;if (subLabel.tag == 8) {subLabel.hidden = NO;}}if ([NSStringFromClass([sub class]) isEqualToString:@"UIImageView"]) {UILabel *subImageView = (UILabel *)sub;if (subImageView.tag == 11) {subImageView.hidden = NO;}}}}}}
}