Xcode 集合视图单元格赢得';我不允许选择

Xcode 集合视图单元格赢得';我不允许选择,xcode,collectionview,Xcode,Collectionview,这可能是一个非常容易解决的问题;我读了无数的论坛和教程,似乎找不到答案 在我的应用程序中,我有一个popover集合视图来选择一个特定选项并返回一个值 但是它不会高亮显示或选择?我可以看到NS日志输出从不显示选择或数据传递 这是我的密码 collection.h文件 @interface collection : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegate>

这可能是一个非常容易解决的问题;我读了无数的论坛和教程,似乎找不到答案

在我的应用程序中,我有一个popover集合视图来选择一个特定选项并返回一个值

但是它不会高亮显示或选择?我可以看到NS日志输出从不显示选择或数据传递

这是我的密码

collection.h文件

@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;
}


这里有很多问题。首先,我认为您混淆了选择代理的方法。
collectionView:performAction:forItemAtIndexPath:withSender:
方法仅适用于特殊菜单弹出窗口,与选择单元格本身无关。您需要在代理中实现以下内容:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Selected cell at index path %@", indexPath);
}
现在您只是实现了取消选择回调


除此之外,还要确保
UICollectionViewCell
中的图像视图已启用触摸功能,否则可能会阻止触摸事件到达该单元格,并且不会触发任何代理调用。我希望这有帮助

这里有很多问题。首先,我认为您混淆了选择代理的方法。
collectionView:performAction:forItemAtIndexPath:withSender:
方法仅适用于特殊菜单弹出窗口,与选择单元格本身无关。您需要在代理中实现以下内容:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Selected cell at index path %@", indexPath);
}
现在您只是实现了取消选择回调

除此之外,还要确保
UICollectionViewCell
中的图像视图已启用触摸功能,否则可能会阻止触摸事件到达该单元格,并且不会触发任何代理调用。我希望这有帮助

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