Recently I was attempting to add controls, some buttons and stuff, beneath a UITableView. Sounds simple right? Actually, in the end it kind of was simple, but if you’ve not used the technique before it might not be obvious.

There are probably many solutions, this is one of them.

The solution boils down to: make a subview of UITableView and pass the touches through the contentInset.top.

@interface HQForwardTouchTableView : UITableView
// Nothing is needed here
@end

@implementation HQForwardTouchTableView

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
	// The Y will be 0 at the start of the content 
	// i.e. the end of the contentInset.top
	if( point.y < 0 ){ 
		return NO;
	}
	// Otherwise it is a normal touch
	return YES;
}

@end

Then we just set the contentInset to the height of our controls that we want to display behind it. To be clear, the table view will have the same Y as the controls.

This is not the most clear image, but here you can see that the tableview (selected blue area) is above the controls.

image1

This is the result:

image2gif

For this I’ve added scrollRectToVisible (within the method above before returning NO). I also faded the controls when scrolling to indicate some form of depth.