views:

1168

answers:

2

It seems like if this method will be called any time the user touches my view:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    if ([touch view] == self && [touch tapCount] >= 1) {
     // do something...
    }
}

I've implemented this in an UIScrollView. The documentation for UIEvent doesn't mention those touchUpInside, touchUpOutside, etc. events that are available in Interface Builder when making connections to action methods.

Actually I want a method to be called only upon one of those "touchUpInside" events, rather than on any kind of touch.

+3  A: 

You want touchesEnded:withEvent:. The touchesBegan method gets called when a touch or series of touches starts within a UIResponder; the touchesEnded method gets called when that batch of touches is done (i.e. your user stops touching the screen/lifts a finger).

Tim
+2  A: 

The canonical way is to create an IBAction and hook it up to the touchUpInside event in InterfaceBuilder.app.

Everything time a touchUpInside happens, your IBAction will be called.

If you are creating programmatically, outside of IB, you can still hook up the IBAction.

Kailoa Kadano
I create 20 images in a grid, which extends dynamically as the user scrolls. How would I hook those up to an IBAction? IB would have to know in which view that happens, right? How could I tell IB that "generically"?
Thanks
Check out the UIControl class ref and addTarget:action:forControlEvents:
Kailoa Kadano