iPhone UITableView - Delete Button

后端 未结 6 1637
-上瘾入骨i
-上瘾入骨i 2020-11-27 10:41

I am using the \'swipe to delete\' functionality of the UITableView.

The problem is I am using a customised UITableViewCell which is create

6条回答
  •  萌比男神i
    2020-11-27 11:30

    I don't know the final solution, but as far as I tried the following code might be useful.

    // subclass UITableViewCell
    
    - (void)willTransitionToState:(UITableViewCellStateMask)state
    {
        [super willTransitionToState:state];
    
        if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableCellStateShowingDeleteConfirmationMask)
        {
            for (UIView *subview in self.subviews)
            {
                if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
                {
                    subview.hidden = YES;
                    subview.alpha = 0;
                }
            }
        }
    }
    
    - (void)didTransitionToState:(UITableViewCellStateMask)state
    {
        [super willTransitionToState:state];
    
        if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableCellStateShowingDeleteConfirmationMask)
        {
            for (UIView *subview in self.subviews)
            {
                if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
                {
                    subview.frame = CGRectMake(subview.frame.origin.x - 10, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
                    subview.hidden = NO;
    
                    [UIView beginAnimations:@"anim" context:nil];
                    subview.alpha = 1;
                    [UIView commitAnimations];
                }
            }
        }
    }
    

提交回复
热议问题