Create a Handle for the CollectionView in the UICollectionViewCell
In the .h file of the UICollectionViewCell
@property (nonataomic, retain) UICollectionView *collView;
In the .m file of the UICollectionViewCell
@synthesize *collView;
Then in the implementation File of the Controller in the foll Method set the Collection View
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
YourCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:homePageCollViewCellIdentifier forIndexPath:indexPath];
//NSString *str = [NSString stringWithFormat:@"HP item %d", indexPath.row+1];
cell.collView = self.theCollectionView;
}
Now in the implementation of your UICollectionViewCell
- (void)awakeFromNib
{
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:button];
}
Now in your Button Clicked Method
-(void)buttonClicked:(id)sender
{
NSLog(@"button clicked");
NSIndexPath *indPath = [collVw indexPathForCell:self];
[collVw.delegate collectionView:self.collVw didSelectItemAtIndexPath:indPath];
}