Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell not clipping to bounds in editing mode in iOS8 (works in iOS7.1)

I am setting the height of a UITableViewCell so that it will clip and not all the content for the row is visible. This works fine in iOS7 both "not edit" mode and "edit" mode. In iOS8 it is only working in "not edit" mode. When editing the entire content of the cell is shown after the red delete button on the left is tapped so that you see the delete button on the right.

I had been setting cell.clipsToBounds = YES and thought this was all I needed to do.

EDIT: I also tried cell.contentView.clipsToBounds = YES but this didn't work.

iOS7: (this is what I want)

enter image description here

iOS8:

enter image description here

like image 586
ToddB Avatar asked Dec 11 '14 20:12

ToddB


2 Answers

I tried Vitaliy and ToddB's solutions and unfortunately they were not always 100% consistent for me although they did work most of the time.

I hate to have to override layoutSubviews but I've found no other solution that works 100% of the time thus far :'(

override func layoutSubviews() {
    super.layoutSubviews()
    self.contentView.clipsToBounds = true
}
like image 131
anders Avatar answered Nov 01 '22 07:11

anders


Looks like the UITableView in iOS 8 set cell.contentView.clipToBounds to NO when begin editing. This code help me resolve your issue:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.contentView.clipsToBounds = YES;
}
like image 26
Vitalii Gozhenko Avatar answered Nov 01 '22 07:11

Vitalii Gozhenko