繁体   English   中英

如何在自己的图像视图中打开集合视图中的图像?

[英]How do I open an image from a Collection View in its own Image View?

我正在制作一个应用程序,我将图像保存在数据库中,并附上详细信息。 我使用集合视图来显示图像,现在我希望能够单击一个并在图像视图中的新页面上显示它,以便我可以提供该图像的详细信息并将其保存在数据库中。

任何帮助将非常感激。

您应该实现以下UICollectionViewDelegate方法:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{
     //retrieve image from your array
     //push new view controller/perform segue with image
}

有很多方法可以实现这一点,我想说如果你使用的是故事板,请用ImageView轻松制作另一个视图控制器,并从CollectionViewCell创建一个push segue到新创建的ViewCOntroller,最后,你将不得不使用这样的东西“示例码”

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([sender isKindOfClass:[UICollectionViewCell class]]) {
        if ([segue.identifier isEqualToString:@"??"]) {
            if ([segue.destinationViewController respondsToSelector:@selector(setImage:)]) {
                [segue.destinationViewController performSelector:@selector(setImage:)
                                                      withObject:YOUR CELL IMAGE];
            }
        }
    }
}

不要忘记使用Push Segue Identifier,否则它将无效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM