开发者

How to correctly detect touches in my UIView?

I'm having a problem. I have a UIView, that looks like this :

How to correctly detect touches in my UIView?

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>开发者_JAVA百科

@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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜