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 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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With