tags:

views:

227

answers:

3

Ok, I'm a objective c noob. I have a table view with a tableHeaderView and I want it to respond to touches?

Here are some steps that I do when creating the view: 1. create a view 2. add a bunch of labels and imageviews to it 3. set my tableHeaderView to the view I created

Any help will be appreciated!

A: 

The header view can respond to touches the same way any other view can. You can put buttons on it or you can override the UIResponder methods that handle touch events, specifically:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
Elfred
A: 

add a bunch of labels and imageviews to it

Might want to be careful about that from a user interface design perspective. The effective touch area of a table header is rather small. You don't want it to have more than one or at most two components or possible actions. Otherwise, your users will need a stylus to do anything.

If you just need an image/text and to respond to taps, consider using a UIButton. It will provide you with all that functionality without subclassing.

TechZen
The height of a table header is completely configurable, and the type of the view within it is also configurable. On what basis do you suggest the effective touch area is small?
Amagrammer
A: 

Is the desired touch behavior especially complex? If not, just make the part of the header that needs to respond to touches a button, slider, switch or other control.

Amagrammer