How to remove a view in Stage?
add a view:
mediatorMap.map(Login).toMediator(LoginMediator);
contextView.view.addChild(new Login);
but,how to remove `Login` and release the `LoginMediator`?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by yellow.as on 04 May, 2013 07:23 AM
like the `Login panel`,when I was login,I don't need it after login,
what's the right way to destroy the view `Login panel` ?
I know Mediator has a function named `destroy()`,but how to destroy Mediator's view? just use `contextView.removeClild(someMediator.view)` ?
Support Staff 2 Posted by Ondina D.F. on 04 May, 2013 09:23 AM
The usual way to destroy a view is to let the parent of that view remove it from stage.
In your case, let’s say that the parent view is MainView mapped to MainMediator.
MainView has 2 methods, addLoginView() and removeLoginView().
In addLoginView() you add LoginView to the stage. LoginMediator will be created automatically.
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.
Does this answer your question?
3 Posted by yellow.as on 04 May, 2013 09:40 AM
thank you Ondina D.F.
I just write this in Mediator when the view need remove
I think this is the way with your suggestion
Support Staff 4 Posted by Shaun Smith on 04 May, 2013 10:00 AM
You should not call
destroy()
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: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).
5 Posted by yellow.as on 04 May, 2013 10:03 AM
@Shaun Smith
Got it,it's so simple,thank you.
Support Staff 6 Posted by Shaun Smith on 04 May, 2013 10:17 AM
My pleasure! I'm going to close this as resolved.
Shaun Smith closed this discussion on 04 May, 2013 10:17 AM.