0

This is probably a really easy fix; I have been reading countless forums and tutorials and can't seem to find answer.

In my app I have a popover collection view to select a specific option and return a value...

However it won't highlight or select? I can see the NS Log Outputs never show a selection or datapass.

Here is my code...

collection.h file

@interface collection : UICollectionViewController <UICollectionViewDataSource,     UICollectionViewDelegate>

@property (nonatomic, retain) NSArray  *counterImages;
@property (nonatomic, retain) NSArray  *descriptions;
@property (nonatomic, weak)   UILabel *graniteselect;
@property (nonatomic, retain) UIPopoverController* _collectionPopOver;
@property (nonatomic) BOOL clearsSelectionOnViewWillAppear; // defaults to YES, and if    YES, any selection is cleared in viewWillAppear:
@property (nonatomic) BOOL allowsSelection;

@end


implementation file:



#pragma mark UICollectionViewDataSource

-(NSInteger)numberOfSectionsInCollectionView:
(UICollectionView *)collectionView
{
return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return _descriptions.count;

}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
             cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *myCell = [collectionView
                                dequeueReusableCellWithReuseIdentifier:@"MyCell"
                                forIndexPath:indexPath];

UIImage *image;
int row = [indexPath row];

image = [UIImage imageNamed:_counterImages[row]];

myCell.imageView.image = image;

myCell.celltext.text= [_descriptions objectAtIndex:row];

return myCell;

}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action        forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
_graniteselect.text = [_descriptions objectAtIndex:row];
 [self._collectionPopOver dismissPopoverAnimated:YES];

NSLog(@"Setting Value for Granite Select");

}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:    (NSIndexPath *)indexPath {
// TODO: Deselect item
}



-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
RoleDetailTVC *destination =
[segue destinationViewController];

destination.graniteselect = _graniteselect;

NSLog(@"Passing Data to RoleDetailTVC");

}
@end
user1952602
  • 1
  • 1
  • 2

1 Answers1

3

There are a number of issues here. Firstly, I think you mixed up the delegate methods for selection. The collectionView:performAction:forItemAtIndexPath:withSender: method is only for special menu popovers and has nothing to do with selecting a cell per se. What you need to implement in your delegate is this:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Selected cell at index path %@", indexPath);
}

right now you're just implementing the deselect callback.

Beyond that, also make sure that your image view in the UICollectionViewCell has touches enabled, otherwise you might be blocking touch events to reach the cell and it won't fire any delegate calls. I hope that helps!

DaGaMs
  • 1,521
  • 17
  • 26