ios - Assign UIImage to UIImageView between classes -


*i need viewcontroller have copy of image hold onto disappearing after presentviewcontroller dismissed – *


i have uiviewcontroller i'm calling presentviewcontroller (modalviewcontroller) xib. inside xib, have uiimageview, can markup marker (draw onto). problem when dismiss presentviewcontroller, variable set (a uiimage) goes nil, , can't set markup image onto uiimageview on main uiviewcontroller.

drawing code:

uitouch *touch = [touches anyobject]; currentpoint = [touch locationinview:drawimage];  uigraphicsbeginimagecontext(drawimage.frame.size); [drawimage.image drawinrect:cgrectmake(0, 0,                                        drawimage.frame.size.width,                                        drawimage.frame.size.height)]; cgcontextsetlinecap(uigraphicsgetcurrentcontext(), kcglinecapround); cgcontextsetlinewidth(uigraphicsgetcurrentcontext(), 5.0); cgcontextsetrgbstrokecolor(uigraphicsgetcurrentcontext(), red, green, blue, 1.0); cgcontextbeginpath(uigraphicsgetcurrentcontext()); cgcontextmovetopoint(uigraphicsgetcurrentcontext(), lastpoint.x, lastpoint.y); cgcontextaddlinetopoint(uigraphicsgetcurrentcontext(), currentpoint.x, currentpoint.y); cgcontextstrokepath(uigraphicsgetcurrentcontext()); drawimage.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();  //savve drawings on image uiimage savedmarkup = drawimage.image; lastpoint = currentpoint; 

i've tried 2 methods, a , b, of code set image drawn onto main uivc.

method works if remove line above uigraphicsendimagecontext, if remove line, face many memory warnings , crash after drawing, expected.

method a: uigraphicsbeginimagecontextwithoptions(aview.drawimage.bounds.size, no, 0.0);

[aview.drawimage.image drawinrect:cgrectmake(0, 0,                                             aview.drawimage.frame.size.width,                                             aview.drawimage.frame.size.height)]; uiimage *savedmarkup = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();  aview.annotatedimage.image = savedmarkup; [annotation dismissviewcontrolleranimated:yes completion:nil]; 

method b:

aview.annotatedimage.image = aview.savedmarkup;  

with method b, if nslog value of aview.savedmarkup - logs "(null)".

i've been rattling figure 1 out! very appreciated!

this issue imageview not instantiated... 1 way of handling might lazy instantiation in presenting view controller class. way follows...

make public property on view controller presenting modal view.

so in myclass.h file

@property (strong, nonatomic) uiimage *annotatedimage; 

then, before dismissing view controller write.

(myclass *) presentingcontroller = (myclass *) self.presentingviewcontroller presentingcontroller.annotatedimage = annotatedimage; 

and want in in completion handler...

[self dismissviewcontrolleranimated:yes completion:^{ /* handle here */}]; 

or in viewdidappear:

if (annotatedimage){    // action here such allocating image view , setting image  } 

and presenting view controller have copy of image hold onto , want with.

edit

and of course, make sure drawing code works.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -