"收藏夹视图"单元格不允许我选择



这可能是一个非常容易的修复;我一直在阅读无数的论坛和教程,似乎找不到答案。

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

但是它不会突出显示或选择?我可以看到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;

}

- (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

这里有很多问题。首先,我认为你混淆了选择的委派方法。collectionView:performAction:forItemAtIndexPath:withSender:方法仅用于特殊的菜单弹出窗口,与选择单元格本身无关。你需要在委托中实现的是:

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

现在你只是在实现取消选择回调。

除此之外,还要确保你的UICollectionViewCell中的图像视图启用了触摸,否则你可能会阻止触摸事件到达单元格,它不会触发任何委托调用。我希望这对你有帮助!

最新更新