tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/2030-how-to-remove-a-view-in-stageRobotlegs: Discussion 2013-05-04T10:17:14Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/266949262013-05-04T07:23:49Z2013-05-04T10:04:02ZHow to remove a view in Stage?<div><p>like the <code>Login panel</code>,when I was login,I don't need
it after login,<br>
what's the right way to destroy the view <code>Login panel</code>
?<br>
I know Mediator has a function named <code>destroy()</code>,but how
to destroy Mediator's view? just use
<code>contextView.removeClild(someMediator.view)</code> ?</p></div>yellow.astag:robotlegs.tenderapp.com,2009-10-18:Comment/266949262013-05-04T09:23:31Z2013-05-04T09:23:31ZHow to remove a view in Stage?<div><blockquote>
<p>what's the right way to destroy the view Login panel?</p>
</blockquote>
<p>The usual way to destroy a view is to let the parent of that
view remove it from stage.</p>
<p>In your case, let’s say that the parent view is MainView
mapped to MainMediator.<br>
MainView has 2 methods, addLoginView() and removeLoginView().<br>
In addLoginView() you add LoginView to the stage. LoginMediator
will be created automatically.</p>
<p>MainMediator adds a listener for a context event, say
LoginEvent.LOGIN_SUCCESSFUL, dispatched by a LoginService, and in
its handler method it accesses MainView’s API,
removeLoginView(), where the view itself removes its child from the
stage. When LoginView gets removed from stage, its mediator,
LoginMediator, will be removed as well.</p>
<p>Does this answer your question?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/266949262013-05-04T09:40:03Z2013-05-04T09:40:04ZHow to remove a view in Stage?<div><p>thank you Ondina D.F.</p>
<p>I just write this in Mediator when the view need remove</p>
<pre>
<code>contextView.view.removeChild(view);
this.view = null;
this.destroy();</code>
</pre>
<p>I think this is the way with your suggestion</p></div>yellow.astag:robotlegs.tenderapp.com,2009-10-18:Comment/266949262013-05-04T10:00:11Z2013-05-04T10:00:11ZHow to remove a view in Stage?<div><p>You should not call <code>destroy()</code> manually. It will be
invoked automatically when the mediator is destroyed (which happens
when its view leaves the stage). This should be all you need:</p>
<pre>
<code>view.parent.removeChild(view);</code>
</pre>
<p>You do not need to set the view reference to null either,
because after the line above the mediator will be free for garbage
collection (as will the view, provided there aren't other
references to it).</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/266949262013-05-04T10:03:37Z2013-05-04T10:03:38ZHow to remove a view in Stage?<div><p>@Shaun Smith</p>
<p>Got it,it's so simple,thank you.</p></div>yellow.astag:robotlegs.tenderapp.com,2009-10-18:Comment/266949262013-05-04T10:17:13Z2013-05-04T10:17:13ZHow to remove a view in Stage?<div><p>My pleasure! I'm going to close this as resolved.</p></div>Shaun Smith