ios - How to pass image to be later saved in another view controller? -


i have imagepickercontroller in main view controller allows user select image. using image, results loaded in table view in same view controller.

when row in table view selected table view controller opened bunch of strings. when row table vc selected, table view controller list of movies tmdb api loaded , user swipes save movie.

in app, core data has relationship of single picture related movies.

so know best way keep track of image selected. know nsuserdefaults not best approach.

you can declare variable on target vc's header file. such as;

@property uiimage* sourceimage; 

before opening target vc, set target vc's image:

targetviewcontroller.sourceimage = [uiimage ....] 

then use inside target vc with:

if (_sourceimage != nil){    _sourceimage // passed image } 

2nd way

considering use singleton.

create new nsobject , name singleton

include init in .m file

+ (id)sharedmanager {     static singleton *sharedmymanager = nil;     static dispatch_once_t oncetoken;     dispatch_once(&oncetoken, ^{         sharedmymanager = [[self alloc] init];     });      return sharedmymanager; }  - (id)init {     if (self = [super init]) {      }     return self; } 

in .h file, define

+ (id)sharedmanager; @property uiimage* mainimage; 

in view controller, #import "singleton.h" initialize singletonand assign image.

at 3rd vc, #import "singleton.h" again

and can reach

singleton* si = [singleton sharedmanager]; si.mainimage = // image. check if it's nil or not before use. 

Comments