Techie
Techie

Reputation: 143

Using background view for UITableViewCell in iOS 7 covers default delete button

I am using background view for UITableviewCell which is an imageview, I am using the image view to achieve two side corners for first and last cell. It is working fine But the problem is when I use this background view, the default cell delete button which comes when we press the tableviewcell default edit button is being covered by the background view.If I give clear color for the background view it is working fine but I want background view to be set.

Is there any idea why the delete button is being covered or hidden by cell background view? It happens in iOS 7 Please help! thanks in advance.

Upvotes: 8

Views: 6004

Answers (6)

ReyJenald
ReyJenald

Reputation: 220

how about instead of using the background view. just use your image as the background patternn color try using this

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:YOUR_IMAGE]];

Upvotes: 4

ios
ios

Reputation: 29

I was facing the same issue and finally got solution. Try this: Instead of calling setBackgroundImage in cellForRowAtIndexPath (Delegate Method). Call it in willDisplayCell:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellList.png"]];
}

Enjoy Coding

Upvotes: 1

smileyborg
smileyborg

Reputation: 30469

I spoke with an Apple UIKit engineer today at the iOS 7 Tech Talks event in SF, and confirmed that this is an open bug that will be fixed "soon" by Apple.

UPDATE 10/22/13: iOS 7.0.3 fixes this issue.

Upvotes: 2

idStar
idStar

Reputation: 10804

Workaround

I found an answer in the Apple Developer Forums for a workaround. I've built on that to handle both the case for backgroundView and selectedBackgroundView.

I still see this issue in production iOS7.0.2. This workaround however, is simple and fixes the issue (for me). Drop this code into your custom UITableViewCell subclass.

You can also find it at this gist: https://gist.github.com/idStar/7018104

- (void)layoutSubviews {
    [super layoutSubviews];

    [self applyEditingModeBackgroundViewPositionCorrections];
}


/**
 When using a backgroundView or selectedBackgroundView on a custom UITableViewCell 
 subclass, iOS7 currently 
 has a bug where tapping the Delete access control reveals the Delete button, only to have 
 the background cover it up again! Radar 14940393 has been filed for this. Until solved, 
 use this method in your Table Cell's layoutSubviews
 to correct the behavior.

 This solution courtesy of cyphers72 on the Apple Developer Forum, who posted the
 working solution here: https://devforums.apple.com/message/873484#873484
 */
- (void)applyEditingModeBackgroundViewPositionCorrections {
    if (!self.editing) { return; } // BAIL. This fix is not needed.

    // Assertion: we are in editing mode.

    // Do we have a regular background view?
    if (self.backgroundView) {
        // YES: So adjust the frame for that:
        CGRect backgroundViewFrame = self.backgroundView.frame;
        backgroundViewFrame.origin.x = 0;
        self.backgroundView.frame = backgroundViewFrame;
    }

    // Do we have a selected background view?
    if (self.selectedBackgroundView) {
        // YES: So adjust the frame for that:
        CGRect selectedBackgroundViewFrame = self.selectedBackgroundView.frame;
        selectedBackgroundViewFrame.origin.x = 0;
        self.selectedBackgroundView.frame = selectedBackgroundViewFrame;
    }
}

What we're basically doing here, is resetting the x-origin of these background views to zero at table cell layout time, if they are in editing mode. Why they are translated incorrectly, and why they are above the Apple provided 'Delete' button view is presumably, part of the known issue Apple is working to fix.

Upvotes: 1

Avishay Cohen
Avishay Cohen

Reputation: 2428


Had the exact same issue. Solved it by sending the backgroundView to back when transition starts & also again on the next runloop cycle (using dispatch_async).

Here's the code you should add to your cell class .m file (i.e. MyCustomTableCellView.m)

// Fix for iOS7, when backgroundView comes above "delete" button
- (void)willTransitionToState:(UITableViewCellStateMask)state {
    [super willTransitionToState:state];
    [self sendSubviewToBack:self.backgroundView];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self sendSubviewToBack:self.backgroundView];
    });
}

- (void)didTransitionToState:(UITableViewCellStateMask)state {
    [super didTransitionToState:state];
    [self sendSubviewToBack:self.backgroundView];
}

Upvotes: 3

Dipen Chudasama
Dipen Chudasama

Reputation: 3093

Try below code may be help you.

[youttablecell sendSubviewToBack:yourimageview]

Upvotes: 0

Related Questions