The correct place to handle the stacking order of your red square is in the layoutSubviews method. A table view sends itself layoutSubviews anytime it adds or removes subviews (and at other times).
You need to make a subclass of UITableView that has a link to the red square:
@interface MyTableView : UITableView @property (weak, readonly) IBOutlet UIView *redSquare; @end
You can initialize redSquare any way. I simply placed it in my fir along with the table view and moved it to the table subzone in awakeFromNib :
@implementation MyTableView @synthesize redSquare = _redSquare; - (void)awakeFromNib { [self addSubview:self.redSquare]; }
In any case, to ensure that the red square is always on top of the table cells and grid lines, override layoutSubviews as follows:
- (void)layoutSubviews { [super layoutSubviews]; [self bringSubviewToFront:self.redSquare]; }
rob mayoff
source share