views:

470

answers:

2

Hello guys, I'm having a problem. I have a UIView, that looks like this : alt text

In that view controller I implemented the "touchesBegan:withEvent:" method, but the method is only getting triggered when I touch the bar at the bottom of the view , nothing happens when I touch the table.

How could I change this behavior to be able to detect the touches that occur in the table too ?

This is the code that basically declares that UIViewController:

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

@interface TripSearchDetailViewController : UIViewController 
{
    //Parent of this sub-view.
    UIViewController    *parentController;

    //GUI elements
    UITableView         *tableView;
    UIButton            *backButton;
}

//Button actions
- (IBAction) goBack:(id) sender;
- (IBAction) showDatePicker:(id) sender;

//Class Methods.
- (void) presentDatePicker;


@property (nonatomic, retain) UIViewController      *parentController;
@property (nonatomic, retain) IBOutlet UITableView  *tableView;
@property (nonatomic, retain) IBOutlet UIButton     *backButton;

@end
+2  A: 

It looks like you've got a UITableViewController, not a UIViewController. Your table view is intercepting and handling touches before they make it up to your view controller. You'll need to subclass UITableView, override it's -touchesBegan:withEvent: method, and then create a standard UIViewController that adds your new subclass to the view hierarchy.

Ben Gottlieb
@Ben: I'm pretty sure this class is a UIViewController ( Edited my post to add the code of the @interface of this class ). Though, I added the UITableView with interface builder ( not programmatically ), maybe this could be the problem ?
Mr.Gando
If it's a UIViewController, then just replace your UITableView with a custom subclass of UITableView that overrides -touchesBegan:withEvent:.
Ben Gottlieb
A: 

I think it could possibly help to implement the method hitTest:withEvent: in your TripSearchDetailViewController. If you just return true in this method your touch should be recognized. see also: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html

Shingoo