Search code examples
iphoneiphone-sdk-3.0uinavigationcontrolleruitouch

touchesBegan and other touch events not getting detected in UINavigationController


In short, I want to detect a touch on the navigation controller titlebar, but having trouble actually catching any touches at all!

Everything is done without IB, if that makes a difference.

My app delegate's .m file contains:

MyViewController *viewController = [[MyViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:navigationController.view];

There are a few other subviews added to this window in a way that overlays navigationController leaving only the navigation bar visible.

MyViewController is a subclass of UIViewController and its .m file contains:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
 for (UITouch *touch in touches) {
  NSLog(@"ended\n");
 } 

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 for (UITouch *touch in touches) {
  NSLog(@"began\n");
 } 
}

I also tried putting these functions directly into app delegate's .m file, but the console remains blank.

What am I doing wrong?


Solution

  • Well, for lack of a better idea, I added another subview to my app, clear in color, placed programmatically over the navigation bar title and used a custom class for that view with relevant touch methods overridden. Works fine, but the I still wish there was a more elegant solution.