Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't see dynamic subview on iOS7(Working on iOS6)

I have a custom TableViewCell. In the cell, I add two cross icons (using unicode) to both sides of the cell. when the user pans the cell, it will display the cross icon on the side.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // add a cross
        _crossLabel = [self createCueLabel];
        _crossLabel.text = @"\u274C";
        _crossLabel.textAlignment = NSTextAlignmentLeft;
        // none of the following code works
        [self insertSubview:_crossLabel aboveSubview:self];
        [self insertSubview:_crossLabel belowSubview:self];
        [self addSubview:_crossLabel];

        _crossLabel2 = [self createCueLabel];
        _crossLabel2.text = @"\u274C";
        _crossLabel2.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_crossLabel2];

        // add a pan recognizer
        UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
        recognizer.delegate = self;
        [self addGestureRecognizer:recognizer];
    }
    return self;
}

I used the code above to achieve that. And the _crossLabel did add to the Custom TableView Cell.

I used Reveal App to check the layout of my iOS app enter image description here I can see _crossLabel has been added to my Cell. But I can't see the cross icon in my iOS 7 simulator. I have tried different methods to add the subView, but none of them works.

enter image description here

But it works perfectly on iOS6 and the layout is exactly same as iOS 7 when I check in Reveal App.

Thanks for your help.

like image 835
Jake Lin Avatar asked Dec 26 '22 20:12

Jake Lin


1 Answers

Make sure you are adding to the cell's contentView, [self.contentView addSubView:_crossLabel2]; and not the cell itself. You will see when using Reveal and inspecting iOS7, that in a UITableViewCell UIKit has added/slipped in a UITableViewCellSCrollView above the cell view, so be careful with your insertSubview:belowSubview calls. Also from your screenshot of the OutlineView of Reveal, the 'LocationCell' view is greyed out, which means it is hidden.

Edit just for future reference:
In iOS 7 the new UITableViewCellScrollView has it's 'clipToBounds' property set. It's a hack but if you [self.contentView.superview setClipsToBounds:NO] . The superview is the UITableViewCellScrollView on iOS7 and the cell itself on iOS6

like image 117
theraven Avatar answered Dec 28 '22 10:12

theraven