views:

245

answers:

1

I've been asked to create a custom UITableViewCell with multiple areas that can be tapped.

These areas won't have buttons or any graphics - they'll be invisible. 3 different methods will be called depending on which third of the cell the user taps i.e.

|| decrementFooCount || viewFooDetails || incrementFooCount ||

The cell has a few labels on it that need to be visible at all times - the fooName and fooCount.

I'm thinking perhaps three hidden UIButtons over the cell?

I also need to maintain the swipe to delete default behavior.

+1  A: 

You can subclass your UITableViewCell and override the touchesBegan:event: method. You can then get a CGPoint of where the touch was placed.

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

   if (CGRectContains(myTestRect, location)) {
       // Touched inside myTestRect, do whatever...
   } else {
      // Let the default implementation take over.
      [super touchesBegan:touches event:event];
   }
}

Andrew

Andrew
This looks good. Thanks!
NiKUMAN