I am making an application in which I am saving images in a database with their details. I used a Collection View to show the images and now i want to be able to click on one and show it on a new page in an Image View so that I can provide details for that image and save them in the database.
Any help will be really appreciated.
You should implement following method of UICollectionViewDelegate:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//retrieve image from your array
//push new view controller/perform segue with image
}
There are many ways to achieve this, i would say if you are using storyboard, smily make another view controller with ImageView, and make a push segue from CollectionViewCell to the new created ViewCOntroller and finally, you will have to use something like this "Example Code"
- (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];
}
}
}
}
Don't forget to put Push Segue Identifier or else, it won't work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.