UITableViewCell content overlaps delete button when in editing mode in iOS7

前端 未结 11 1050
长情又很酷
长情又很酷 2020-12-15 07:50

I am creating a UITableView with custom UITableViewCells. iOS 7\'s new delete button is causing some problems with the layout of my cell.

I

相关标签:
11条回答
  • 2020-12-15 07:58

    If you are putting content in the UITableViewCell's contentView, be sure you use self.contentView.frame.size.width and not self.frame.size.width in layoutSubviews.

    self.frame expands width in editing mode, and will cause any content on the right to extend past the bounds of the contentView. self.contentView.frame stays at the correct width (and is what you should be using).

    0 讨论(0)
  • 2020-12-15 08:01

    try using the accessoryView and editingAccessoryView properties of your UITableViewCell, instead of adding the view yourself.

    If you want the same indicator displayed in both editing and none-editing mode, try setting both view properties to point at the same view in your uiTableViewCell like:

    self.accessoryView = self.imgPushEnabled;
    self.editingAccessoryView = self.imgPushEnabled;
    

    There seems to be a glitch in the table editing animation in IOS7, giving an overlap of the delete button and the accessoryView when switching back to non-editing state. This seems to happen when the accesoryView is specified and the editingAccessoryView is nil.

    A workaround for this glitch, seems to be specifying an invisible editingAccessoryView like:

    self.editingAccessoryView =[[UIView alloc] init];
    self.editingAccessoryView.backgroundColor = [UIColor clearColor];
    
    0 讨论(0)
  • 2020-12-15 08:01

    The problem is that in edit mode the cell's contentView changes in size. So either you have to override layoutSubviews in your cell and support the different frame sizes

    - (void) layoutSubviews
    {
        [super layoutSubviews];
        CGRect contentFrame = self.contentView.frame;
        // adjust to the contentView frame
        ...
    }
    

    or you take the bait and switch to autolayout.

    First I thought setting contentView.clipsToBounds to YES could be an ugly workaround but that does not seem to work.

    0 讨论(0)
  • 2020-12-15 08:03

    My solution is to move whole contentView to the left when Delete button showing:

    override func layoutSubviews() {
        super.layoutSubviews()
    
        if editingStyle == UITableViewCellEditingStyle.Delete {
            var rect = contentView.frame
            rect.origin.x = self.showingDeleteConfirmation ? -15 : 38
            contentView.frame = rect
        }
    }
    
    0 讨论(0)
  • 2020-12-15 08:04

    I've resolved this problem with set up constraints without width only leading and trailing

    0 讨论(0)
  • 2020-12-15 08:06

    Bringing to front UITableViewCellDeleteConfirmationView in the layoutSubviews of the custom cell works for me on iPhone, but not on iPad.

    I have a UITableView in the master part of a splitViewController for the iPad, and in this case the frame of the UITableViewCellDeleteConfirmationView is (768 0; 89 44), instead of (320 0; 89 44)

    So I resize the frame in the layoutSubviews method and this works for me

    - (void)layoutSubviews {
        [super layoutSubviews];
        for (UIView *subview in self.subviews) 
        {
            for (UIView *subview2 in subview.subviews) 
            {
                if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) 
                { 
                    CGRect frame = subview2.frame;
                    frame.origin.x = 320;
                    subview2.frame = frame;
                    [subview bringSubviewToFront:subview2];
               }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题