ios – UICollectionView didSelectRowAtIndexPath不起作用

ios – UICollectionView didSelectRowAtIndexPath不起作用,第1张

概述didSelectRowAtIndexPath方法在我的应用程序中不起作用.我没有使用NSLog打印任何输出: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ PhotoCell *cel dIDSelectRowAtIndexPath方法在我的应用程序中不起作用.我没有使用NSLog打印任何输出:
- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath{    PhotoCell *cell = [collectionVIEw dequeueReusableCellWithReuseIDentifIEr:@"Cell" forIndexPath:indexPath];    PFObject *imageObject = [self.imagefilesArray objectAtIndex:indexPath.row];    PFfile *imagefile = [imageObject objectForKey:@"file"];    [imagefile getDataInBackgrounDWithBlock:^(NSData *data,NSError *error) {        if (!error) {            cell.imageVIEw.image = [UIImage imageWithData:data];        }    }];    return cell;}- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath{        PhotoCell *cell = [collectionVIEw dequeueReusableCellWithReuseIDentifIEr:@"Cell" forIndexPath:indexPath];NSLog(@"dIDSelectRowAtIndexPath");    cell.imageVIEw.image = self.image;    return cell;}

我希望当我点击一个单元格时,选择图像,并将图像赋予self.image.

我们能用segue做到吗?因为我的dIDSelectRowAtIndexPath方法根本不起作用.

-(voID)prepareForSegue:(UIStoryboardSegue *)segue sender:(ID)sender{    if ([segue.IDentifIEr isEqualToString:@"showPhotoDetail"]) {        NSLog(@"SEGUE showPhotoDetail");    UICollectionVIEwCell *cell = sender;    NSIndexPath *indexPath = [self.collectionVIEw indexPathForCell:cell];    PhotoDetailVIEwController *photoDetailVIEwController = (PhotoDetailVIEwController *)segue.destinationVIEwController;        photoDetailVIEwController.truckImage = self.image;    //[UIImage imagenamed:[self.imagefilesArray objectAtIndex:indexPath.row] ];        NSLog(@"%@",photoDetailVIEwController.truckImage);    }}
解决方法 选择Item的方法签名是错误的,正确的方法签名就是这个
- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectItemAtIndexPath:(NSIndexPath *)indexPath

More Info here

编辑

尝试此代码以获取所选图像.

- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectItemAtIndexPath:(NSIndexPath *)indexPath {    PhotoCell *cell = [collectionVIEw cellForItemAtIndexPath:indexPath];    self.image = cell.imageVIEw.image;}

编辑2

-(voID)prepareForSegue:(UIStoryboardSegue *)segue sender:(ID)sender{    if ([segue.IDentifIEr isEqualToString:@"showPhotoDetail"]) {         // get index path of selected cell         NSIndexPath *indexPath = [collectionVIEw.indexPathsForSelectedItems objectAtIndex:0];         // get the cell object         PhotoCell *cell = [collectionVIEw cellForItemAtIndexPath:indexPath];         // get image from selected cell         self.image = cell.imageVIEw.image;    }}
总结

以上是内存溢出为你收集整理的ios – UICollectionView didSelectRowAtIndexPath不起作用全部内容,希望文章能够帮你解决ios – UICollectionView didSelectRowAtIndexPath不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1107693.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存