簡體   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