I am creating a UITableView
with custom UITableViewCell
s. iOS 7\'s new delete button is causing some problems with the layout of my cell.
I
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).
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];
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.
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
}
}
I've resolved this problem with set up constraints without width only leading and trailing
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];
}
}
}
}