【问题标题】:pushing segue on collectionView click在collectionView上推动segue点击
【发布时间】:2014-08-31 20:24:39
【问题描述】:

我已经将我的 collectionViewCell 中的 push segue 连接到情节提要中的 viewController,但是当单击单元格时没有任何反应。我该怎么做才能做到这一点?

prepareForSegue

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


    if ([segue.identifier isEqual:@"toHomeProfile"])
    {
        HomeProfileViewController * dvc = segue.destinationViewController;
        self.selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];

    
        dvc.imageArray = [[NSMutableArray alloc]init];
        dvc.imageArray = [imageDic objectAtIndex:self.selectedIndexPath.item];


    }
}

viewDidLoad

- (void)viewDidLoad
{
   [super viewDidLoad];

    CHTCollectionViewWaterfallLayout *layout = [[CHTCollectionViewWaterfallLayout alloc] init];

    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    layout.headerHeight = 0;
    layout.footerHeight = 0;
    layout.minimumColumnSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    self.collectionView.collectionViewLayout = layout;


    _collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [_collectionView registerClass:[CHTCollectionViewWaterfallCell class]
    forCellWithReuseIdentifier:CELL_IDENTIFIER];

}

【问题讨论】:

  • 你不应该做任何事情。如果转场是由单元格制作的,则不需要任何代码来执行转场。只需确保您的调用是可点击的——例如,如果它有一个图像视图,请确保将其 userInteractionEnabled 设置为 YES(图像视图默认为 NO)。

标签: ios objective-c iphone uicollectionview


【解决方案1】:

查看 UICollectionViewDelegate 协议中的 collectionView:didSelectItemAtIndexPath:

https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionViewDelegate_protocol/Reference/Reference.html

另外,发帖前先用谷歌搜索一下! 3秒的搜索让我找到了

Handling Tap Gesture in a UICollectionView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2015-09-03
    • 2012-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多