In iOS7, the cell.selectedBackgroundView element does not show

Work on converting an iOS6 application to iOS7, and they use this to customize a grouped table style.

    cell.backgroundView = aView;
    cell.selectedBackgroundView = bView;

When the application loads, it loads the backgroundView correctly, but when I click on the cell, selectedBackgroundView no longer works in iOS7. A click selects a cell so that it works, but selectBackgroundView just does not appear.

Any suggestions? The only thing I can think of is not to use selectedBackgroundView and just add and remove subviews to the cell every time they are selected and not selected.

/// UPDATE ///

Put this in my cellForRowAtIndex and still do NOT .

UIView *bgColorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    bgColorView.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez
    bgColorView.layer.masksToBounds = YES;
    cell.selectedBackgroundView = bgColorView;

//// UPDATE 2 ///////////

If I put this in my cellforRowAtIndex

cell.selectedBackgroundView = nil;
    cell.backgroundView = nil;
    UIView *bgColorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    bgColorView.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez
    bgColorView.layer.masksToBounds = YES;
    cell.selectedBackgroundView = bgColorView;

    UIView *bgSColorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    bgSColorView.backgroundColor = [UIColor colorWithRed:(106.0/255.0) green:(201.0/255.0) blue:(255.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez
    bgSColorView.layer.masksToBounds = YES;
    cell.backgroundView = bgSColorView;

show cell.background bgSColorView, , ( BackgroundView ? BackgroundView ?

///UPDATE 3//// setSelectin: animation: ( ).

 UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez
bgColorView.layer.masksToBounds = YES;
self.selectedBackgroundView = bgColorView;

UIView *bgSColorView = [[UIView alloc] init];
bgSColorView.backgroundColor = [UIColor colorWithRed:(106.0/255.0) green:(201.0/255.0) blue:(25.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez
bgSColorView.layer.masksToBounds = YES;
self.backgroundView = bgSColorView;



[super setSelected:selected animated:animated];

, . BOOOM, selectionBackgroundView , .

+3
3

.

, .xib. selectionStyle UITableViewCellSelectionStyleNone.

self.selectionStyle = UITableViewCellSelectionStyleDefault;, selectedBackgroundView .

, .

- (void)awakeFromNib
{
    [super awakeFromNib];

    self.selectionStyle = UITableViewCellSelectionStyleDefault;

    UIView *selectedBackgroundView = [[UIView alloc] init];
    selectedBackgroundView.backgroundColor = [UIColor redColor];
    self.selectedBackgroundView = selectedBackgroundView;
}
+13

, tableView: cellForRowAtIndexPath: UITableViewCell setSelected: :

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    UIImage *image = [UIImage imageNamed:@"selected_cell.png"];
    self.selectedBackgroundView = [[UIImageView alloc]initWithImage:image];
}

, . -. , :

 - (void)setSelected:(BOOL)selected animated:(BOOL)animated
        {
             [super setSelected:selected animated:animated];

            if (selected) {
                contentView.backgroundColor = SharedColors.Blue.ToUIColor ();
            } else {
                contentView.backgroundColor = SharedColors.Black.ToUIColor ();
            }
        }
+2
override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    var view = UIView(frame: self.bounds)
    view.backgroundColor = UIColor.redColor()
    self.selectedBackgroundView = view


}
0
source

All Articles