-3

I want to pass selected UIImage into another viewControllerwithout using segue.

I have UICollectionViewCell ,so when I click on particular cell, selected image will show on another viewController.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ketan Odedra
  • 1,215
  • 10
  • 35
  • Use delegates to do it! – Teja Nandamuri Jul 08 '17 at 13:17
  • can you help me with code? – Ketan Odedra Jul 08 '17 at 13:25
  • 1
    Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jul 08 '17 at 22:09

2 Answers2

1

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];
}
Sathish Kumar VG
  • 2,154
  • 1
  • 12
  • 19
  • or, if you are not using NavigationController, just use `func present(UIViewController, animated: Bool, completion: (() -> Void)? = nil)` on `self` – Milan Nosáľ Jul 10 '17 at 07:54
0

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

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109