I want to pass selected UIImage
into another viewController
without using segue
.
I have UICollectionViewCell
,so when I click on particular cell, selected image will show on another viewController
.
I want to pass selected UIImage
into another viewController
without using segue
.
I have UICollectionViewCell
,so when I click on particular cell, selected image will show on another viewController
.
Try This without segue,
Create @property(nonatomic,strong) UIImage *diplayImage;
in another viewController.h file
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NewController * viewcontroller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"newController"];
viewcontroller.diplayImage = [UIImage imageNamed:@"selectedImage.png"];
[self.navigationController pushViewController:viewcontroller animated:YES];
}
You can use delegates to send data between classes:
First create a delegate:
@protocol ImageSelectDelegate <NSObject>
@required
-(void)selectedImage:(UIImage *)image;
@end
and implement this protocol in the class you want to send your image :
@interface CollectionDetailViewController()< ImageSelectDelegate >
and in the collection controller, create a property for the delegate :
@property (nonatomic, retain) id< ImageSelectDelegate > imageSelectDelegate;
and in the didSelect method, just do:
[self.imageSelectDelegate selectedImage:imageTosend];
In the other class, you can obtain the image in this method:
-(void) selectedImage:(UIImage *)image{
self.image = image;
}
Make sure your imageSelectDelegate is not nil, else this won't work