Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete button is covered by custom cell

Tags:

xcode

ios

ios8

enter image description here

I have an issue in one of my projects. I have one tableview like in the picture. My issue is my custom cell background is overlapping the UITableView delete button. Could any one please help me to bring it to front.

  1. I have used below code but some of the developers are saying that If we use that code Apple may be reject your app

    - (void)layoutSubviews
    {
        [super layoutSubviews];
    
        for (UIView *subview in self.subviews) {
            for (UIView *subview2 in subview.subviews) {
                //NSLog(@"confirm is %@",[subview2 class]);
                if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"])
                {
                    // move delete confirmation view
                    [subview bringSubviewToFront:subview2];
                } else if ([NSStringFromClass([subview2 class]) isEqualToString:@"_UITableViewCellActionButton"])
                {
                    [subview bringSubviewToFront:subview2];
                }
            }
        }
    }
    
  2. another issue is the below code is only working upto iOS 7 but not working in iOS 8.

  3. If I set the - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath; method to YES I don't have issues but we don't want indent.

Any ideas could be very helpful.

like image 639
Tendulkar Avatar asked Dec 26 '22 02:12

Tendulkar


2 Answers

You need to add a button into contentView, not to cell view directly

like image 20
Grzegorz Krukowski Avatar answered Feb 02 '23 01:02

Grzegorz Krukowski


Hierarchy of UITableViewCell subviews is different in iOS 7 and iOS 8, try my solution.

- (void)layoutSubviews {

    [super layoutSubviews];

    for (UIView *subview in self.subviews) {

        // for iOS 8
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
            [self bringSubviewToFront:subview];
            return;
        }



        // for iOS 7
        for (UIView *subview2 in subview.subviews) {
            if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
                [subview bringSubviewToFront:subview2];
                return;
            }
        }

    }
}
like image 50
Lee Jeff Avatar answered Feb 02 '23 01:02

Lee Jeff