views:

87

answers:

1

Hello,

I have the following piece of code that I'm expecting to run on a touch event:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch;
    touch=[touches anyObject];
    CGPoint point=[touch locationInView:self.view];

    if (CGRectContainsPoint([billTotal frame],point))
    {
        [self pickerShow];
    }
}

Its not being executed, any ideas what I'm doing wrong?

Regards, Stephen

A: 

Did you enable touches on the view?

I believe UIImageView has user interaction disabled by default.

If you have a .xib file for the view you can enable touches in Interface Builder by selecting the view, pressing CMD + 1 and checking User Interaction Enabled

In code you can do it like this

myView.userInteractionEnabled = YES;  
Florin
How can I confirm this? I'm looking at the UIView attributes, am I in the correct place ?
Stephen
Sorry just refreshed the screen and saw the rest of your post, please ignore previous question.
Stephen
Yes, User Interaction Enabled is ticked.
Stephen
Maybe then you have another view that's on top of that one. And the one on the top is catching the touch event.
Florin
Ok, I have two UIViews, the second one contains a UIPicker which should appear when the text field is tapped.Is there any way I can check which view is catching the touch event?
Stephen
I am actually basing my code on the following tutorial...http://www.mediafire.com/?wmjc2ffntzc
Stephen
What do you mean by "it is not being executed"? Is the method not called at all or it doesn't go into the if statement. You could check with the debugger or by using some log statements: e.g. NSLog(@"This line has been executed").
Florin
I have a breakpoint set in the debugger, the method is not being called.
Stephen
Well, there are a few more possible causes that I can think of, but none that I am really sure of.I downloaded the tutorial you said you are following. I am not an expert but it doesn't seem to be very well written (in my opinion). I would recommend you to follow the samples provided by Apple. They are probably a better way to learn.You can find at least two sample apps ("MoveMe" and "Touches") here:http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITouch_Class/Reference/Reference.html#//apple_ref/occ/cl/UITouch
Florin