iPhone UITableView - Delete Button

后端 未结 6 1639
-上瘾入骨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条回答
  •  一向
    一向 (楼主)
    2020-11-27 11:21

    For me the best way to solve this was overriding -(void)layoutSubviews in MyCell:UITableViewCell

    Here you can see not only the Delete button custom position, but also repositioning the Edit and Reorder controls for Edit mode

    - (void)layoutSubviews
    {
        [super layoutSubviews];
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDuration:0.0f];
    
        for (UIView *subview in self.subviews) {
    
    
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) { 
                CGRect newFrame = subview.frame;
                newFrame.origin.x = 200;
                subview.frame = newFrame;
            }
            else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {             
                CGRect newFrame = subview.frame;
                newFrame.origin.x = 100;
                subview.frame = newFrame;
            }
            else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellReorderControl"]) {             
                CGRect newFrame = subview.frame;
                newFrame.origin.x = 200;
                subview.frame = newFrame;
            }
        }
        [UIView commitAnimations];
    }
    

提交回复
热议问题