Custom UITableViewCell in edit mode does not move my UILabels

后端 未结 3 929
猫巷女王i
猫巷女王i 2020-12-31 14:25

This is doing my head in:-)

I have a fully functional CoreData Populated UITableView inside a UIViewController and I have successfully impl

3条回答
  •  情书的邮戳
    2020-12-31 14:54

    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];
        }
    }
    

提交回复
热议问题