ios - UICollectionView prepareForSegue 通过手势点击 UIImageView

标签 ios objective-c uicollectionview uigesturerecognizer uistoryboardsegue

我使用 UICollectioView 从网络加载带有 NBMutableArray 的图像并且运行良好。

现在在我的 UIImageView 上添加一个 Tap Gesture Recognizer,我会将信息传递给其他 View ,例如 segue 标识符示例:

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

    if([@"getImage" isEqualToString:segue.identifier]) {
        NSIndexPath *index = [self.collectionView indexPathForCell:sender];
        [[segue destinationViewController] setLinkImg:(arrayCollectionImages)[index.row][@"image"]];
    }

在 MyStoryBoard 中我使用了这个:

enter image description here

如果我只保留这个功能,我的应用程序会在点击图像时崩溃。

任何人都知道如何做到这一点?

最佳答案

无需向 UIImageView 添加 Tap Gesture Recognizer。只需将 CollectionCell 的“Triggered Segues”连接到您的目标 ViewController。这样发件人将是 CollectionCell *- (void)prepareForSegue:(UIStoryboardSegue )segue sender:(id)sender 方法。

enter image description here

关于ios - UICollectionView prepareForSegue 通过手势点击 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21599995/

相关文章:

ios - 快速返回一个带有可选Element的泛型函数中的未包装Element?

javascript - 在 NavigatorIOS 中调用 onRightButtonPress 的函数 - React Native

iphone - NSDictionary 中的 NSDictionary

iphone - 我们可以从应用商店获得唯一的交易ID吗

ios - 选项卡式 View Controller ,切换选项卡后 Collection View 中的scrollToItem不起作用

ios - UIImage 内存未释放 VM : ImageIO_JPEG_DATA?

ios - swift : How can I make UITextView in UITableViewCell firstresponder

ios - Xcode(iOS 应用程序)如何使用私有(private)存储库中托管的 swift 包?

ios - If 语句会导致 iOS 设备崩溃,但不会导致模拟器崩溃

ios - UICollectionView 必须使用非零布局参数进行初始化。 UICollectionView 快速出错