Custom UITableViewCell in edit mode does not move my UILabels
Implement the following methods in your custom cell class.
- (void)willTransitionToState:(UITableViewCellStateMask)state
and
- (void)didTransitionToState:(UITableViewCellStateMask)state
and move your label accordingly.
It should be like
- (void)willTransitionToState:(UITableViewCellStateMask)state {
[super willTransitionToState:state];
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
label.frame = ...
}
}
Edit:
- (void)willTransitionToState:(UITableViewCellStateMask)state {
[super willTransitionToState:state];
// label.hidden = YES;
// label.alpha = 0.0;
}
- (void)didTransitionToState:(UITableViewCellStateMask)state {
[super didTransitionToState:state];
if (state == UITableViewCellStateShowingDeleteConfirmationMask) {
[UIView beginAnimations:@"anim" context:nil];
label.frame = leftFrame;
[UIView commitAnimations];
} else if (state == UITableViewCellStateDefaultMask) {
[UIView beginAnimations:@"anim" context:nil];
label.frame = rightFrame;
[UIView commitAnimations];
}
}
The other solution will probably work but this way will do the animation automatically for you.
MNCustomCell
is not going to re-layout the view depending on the current state of the cell, but if you add your label to the contentView of the cell, it will.
The following example will move the label so it doesn't interfere with the delete button.
MNCustomCell.m
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)]];
mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:mainLabel];