![](/img/trans.png)
[英]How do I pass an image view and its properties from one view controller to another?
[英]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.