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

后端 未结 6 506
[愿得一人]
[愿得一人] 2021-01-12 02:38

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 t

相关标签:
6条回答
  • 2021-01-12 03:16

    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.

    0 讨论(0)
  • 2021-01-12 03:25


    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];
    }
    
    0 讨论(0)
  • 2021-01-12 03:32

    Try below code may be help you.

    [youttablecell sendSubviewToBack:yourimageview]
    
    0 讨论(0)
  • 2021-01-12 03:33

    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]];
    
    0 讨论(0)
  • 2021-01-12 03:33

    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.

    0 讨论(0)
  • 2021-01-12 03:34

    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

    0 讨论(0)
提交回复
热议问题