views:

196

answers:

3

This question is a follow on from the following:

http://stackoverflow.com/questions/3235967/uitouch-event-not-responding

I done more research and I know what the problem is, but I don't know how to solve it or even if it can be solved. I may have to take a new approach.

I have a RootViewController and from this I load a second ViewController using the following code:

[self presentModalViewController:newWorkoutViewController animated:YES];

I then have the following code in place in NewWorkoutViewController:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"New Workout Screen tapped");
}

This method is not being actioned, I think this is because its a modal view. Is there anyway to detect taps on the screen in a modal view.

Thanks Stephen

A: 

Define the relevant methods on your view controller, not on your view.

tc.
They are defined on my View Controller.
Stephen
Problem solved...in NewWorkoutViewController I have two other buttons which can call two other view controllers. I didn't have these setup correctly, so the when the screen was clicked/tapped it wasn't registering.Thanks for the help.
Stephen
I mean view, not view controller, of course...
tc.
+1  A: 

Your assumptions are incorrect. Displaying the view controller modally has nothing to do with it. Touches work the same in a modal view as they do in any other. In all likelihood, you don't have user interaction enabled on your view. How did you create your secondary view controller?

Matt Long
user interactions is enabled. To create the secondary view controller I right clicked on my classes folder and added a NEW FILE, then selecting UIViewController Subclass, With XIB for user interface checked.
Stephen
Problem solved...in NewWorkoutViewController I have two other buttons which can call two other view controllers. I didn't have these setup correctly, so the when the screen was clicked/tapped it wasn't registering.Thanks for the help.
Stephen
@Stephen: I've got the same problem right now, where I want to dismiss a modal view when the user taps outside of it (it's a "form" style view so it only covers the center of the iPad) -- what exactly was the problem with your buttons?
Kalle
+1  A: 

Events are only sent to the ViewController if there are no controls in the view to receive the events. For example, if you have a button in your view, and touch the button, the button gets the touch event, not the ViewController.

The OS determines where to send events using the pointInside:withEvent: method and then calling hitTest:withEvent: It's possible to override these in your view and see what objects are getting the events.

Also, any views that are hidden, that have disabled user interaction, or have an alpha level less than 0.1 are ignored by hitTest:withEvent:

progrmr
Thanks for this I understand what your saying, if you have a moment could you take a look at this sample code...http://www.mediafire.com/?wmjc2ffntzcUltimately I want to achieve this, based on what you said above I don't understand how this guy achieved the touch event on the text box i.e. when the textbox is clicked, the Picker popups.
Stephen