title: UIButton in cell in collection view not receiving touch up inside event
body: <p>The following code expresses my problem: 
  (It's self-contained in that you could create a Xcode project with an empty template, replace the contents of the main.m file, delete the AppDelegate.h/.m files and build it)</p>
  
  <pre><code>//
  //  main.m
  //  CollectionViewProblem
  //
  
  
  #import &lt;UIKit/UIKit.h&gt;
  
  @interface Cell : UICollectionViewCell
  
  @property (nonatomic, strong) UIButton *button;
  @property (nonatomic, strong) UILabel *label;
  
  @end
  
  @implementation Cell
   - (id)initWithFrame:(CGRect)frame
  {
      if (self = [super initWithFrame:frame])
      {
          self.label = [[UILabel alloc] initWithFrame:self.bounds];
          self.label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
          self.label.backgroundColor = [UIColor greenColor];
          self.label.textAlignment = NSTextAlignmentCenter;
  
          self.button = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
          self.button.frame = CGRectMake(-frame.size.width/4, -frame.size.width/4, frame.size.width/2, frame.size.width/2);
          self.button.backgroundColor = [UIColor redColor];
          [self.button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
          [self.contentView addSubview:self.label];
          [self.contentView addSubview:self.button];
      }
      return self;
  }
  
  
  // Overriding this because the button's rect is partially outside the parent-view's bounds:
  - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
  {
      if ([super pointInside:point withEvent:event])
      {
          NSLog(@"inside cell");
          return YES;
      }
      if ([self.button
           pointInside:[self convertPoint:point
                                   toView:self.button] withEvent:nil])
      {
          NSLog(@"inside button");
          return YES;
      }
  
      return NO;
  }
  
  
  - (void)buttonClicked:(UIButton *)sender
  {
      NSLog(@"button clicked!");
  }
  @end
  
  @interface ViewController : UICollectionViewController
  
  @end
  
  @implementation ViewController
  
  // (1a) viewdidLoad:
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      [self.collectionView registerClass:[Cell class] forCellWithReuseIdentifier:@"ID"];
  }
  
  // collection view data source methods ////////////////////////////////////
  
  - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  {
      return 100;
  }
  
  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ID" forIndexPath:indexPath];
      cell.label.text = [NSString stringWithFormat:@"%d", indexPath.row];
      return cell;
  }
  ///////////////////////////////////////////////////////////////////////////
  
  // collection view delegate methods ////////////////////////////////////////
  
  - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  {
      NSLog(@"cell #%d was selected", indexPath.row);
  }
  ////////////////////////////////////////////////////////////////////////////
  @end
  
  
  @interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt;
  
  @property (strong, nonatomic) UIWindow *window;
  
  @end
  
  @implementation AppDelegate
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  
      UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
      ViewController *vc = [[ViewController alloc] initWithCollectionViewLayout:layout];
  
  
      layout.itemSize = CGSizeMake(128, 128);
      layout.minimumInteritemSpacing = 64;
      layout.minimumLineSpacing = 64;
      layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
      layout.sectionInset = UIEdgeInsetsMake(32, 32, 32, 32);
  
  
      self.window.rootViewController = vc;
  
      self.window.backgroundColor = [UIColor whiteColor];
      [self.window makeKeyAndVisible];
      return YES;
  }
  
  @end
  
  
  int main(int argc, char *argv[])
  {
      @autoreleasepool {
          return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
      }
  }
  </code></pre>
  
  <p>Basically I'm creating a Springboard-type UI using collection views. My <strong>UICollectionViewCell</strong> subclass (<strong>Cell</strong>) has a button which lies partially outside the cell's <em>contentView</em> (i.e. its superview's) bounds.</p>
  
  <p>The problem is that clicking on any part of the button outside of the <em>contentView</em> bounds (basically 3/4th of the button) doesn't invoke the button action. Only when clicking on the portion of the button that overlaps the <em>contentView</em> is the button's action method called.</p>
  
  <p>I've even overridden <code>-pointInside:withEvent:</code> method in <strong>Cell</strong> so that touches in the button will be acknowledged. But that hasn't helped with the button clicking problem. </p>
  
  <p>I'm guessing it might be something to do with how <strong>collectionView</strong> handles touches, but I don't know what. I know that <strong>UICollectionView</strong> is a <strong>UIScrollView</strong> subclass and I've actually tested that overriding <code>-pointInside:withEvent:</code> on a view (made subview to a scroll view) containing a partially overlapping button solves the button clicking problem, but it hasn't worked here.</p>
  
  <p>Any help?</p>
  
  <p>** Added:
  For the record, my current solution to the problem involves insetting a smaller subview to <em>contentView</em> which gives the cell its appearance. The delete button is added to the <em>contentView</em> such that its rect actually lies within the bounds of contentView but only partially overlaps the visible part of the cell (i.e. the inset subview). So I've got the effect I wanted, and the button is working properly. But I'm still curious about the problem with the original implementation above.</p>