Let's use an example of a blog built by Marionett. The blog post is a sub app and hook the route post/:id. It also has a controller, inherited from Marionette.Controller. Quite normal.
Each hit to post/:id will create a new controller instance, managing the related model and views. The controller instance will trigger App.vents but won't listen on App.vents.
My question is, since there will be so many instances of the controller created when an user navigates around, should I concern the close of the instances when there are a close() method available in controller? Will there be memory leak if not closing them?
Thanks.
There could be a memory leak depending on what's inside your controllers. Also if you're controller is using listenTo to watch events on other models/objects you could get a build up of zombie events. Without seeing your code it would be hard to say for sure.
In general, I think why not just close the controllers? The way I do this (from BackboneRails tutorials) is to have the first view controller the renders (typically a layout) as the main view and then bind to the view's close event--when the view closes the controller will call close on itself. You can build this into your base controller so it happens automatically. This has worked pretty well for me...
Related
I need to perform an action after switching to a view.
The first time you switch to a view 'activate' and then 'compositionComplete' is called.
After that only 'activate' is called.
It would appear that 'activate' is called before the view has finished being displayed and this is causing issues with a JavaScript control I'm using (Bing Maps V7).
I've been using Hooking Lifecycle Callbacks as a reference but there doesn't appear to be a suitable callback to hook in to.
Is there another event or approach I can use to tell when the DOM has finished changing to the view?
It sounds as though your module is a singleton instead of an instance. Is that true? If you create an instance-based module, the module will be created anew each time it's activated. That will cause the compositionComplete to re-execute.
The activate handler is good for preparing data that will ultimately be displayed in the view. compositionComplete is best for handling matters that depend on a fully-constructed DOM.
We use Bing Maps AJAX v7 as well, and I've always placed it in an instance-based module.
To create an instance-based module, if you're not familiar, make sure your viewmodel returns a constructor function instead of an object literal.
Have you tried placing the Bing initialization in attached? Or creating a custom binding for it? Any third party libraries i use will always be initialized in attached, and if its something i want to use more than once, ill either create a custom binding for it or create a widget.
TL:DR - How do I create Relationship Segues in Xcode 4.4?
Hello everyone, I have an app where I want to add some tabbing behaviour to one of my controllers but, due to design decisions, I can't use UITabbar. I already know about using a UIToolbar with a UISegmented control inside it, but where I'm having difficulty, is how to switch between view controllers.
I know I can't use normal segues (since each tab change would keep stacking a new controller on top of the previous), but UITabBar has something called "Relationship Segues". I looked around but couldn't figure out how to create one.
Does anyone know how do it? Also, is there a better way to approach this problem?
Thanks
I've done the exact same thing recently. I've created a container view controller, SegmentedViewController, and added the view controllers I wanted to switch between to my container controller using addChildViewController. Upon switching view controller (I used target/action on my UISegmentedControl), you call transitionFromViewController:toViewController:duration:options:animation:completion. That's the general idea. Look at the "Implementing a Container View Controller" section here for implementation details.
I'm not sure if the question title really explains what I want to do, however I will explain below:
I am using the Visual Studio MVC project template and I have changed some of the tabs to map to different actions from different controllers. However I want to make one of the tabs to open a view that will again have links for different administration actions.
The problem I have is that I am unsure where to place this view as it doesn't really belong to an admin controller as each tab on this view will link to a list view in another controller. In effect it is a sub _Layout view, as it doesn't have anything to do with a controller.
I hope I have made myself clear enough!
You can place this view in the Shared folder since it will be used by multiple controllers. Or, you could place it somewhere else and reference it by using the full path to this View/Partial View
In a Controller
public ActionResult SomeAction(){
return View("~/Path/To/View/ViewName.cshtml");
}
In a View (Razor)
#Html.RenderPartial("~/Path/To/View/ViewName.cshtml");
With that said, the Shared folder makes the most sense since it will be shared across multiple controllers.
I'm asking this because I really don't know where I should handle events of my dynamically created window.
When someone clicks on a desktop icon, the window (if it doesn't exist) will be dynamically created. Should I create a controller when creating the window and hook to it? If yes, how?
Here you can read different approaches I've thought about:
Create a controller that will instanciate the Window (as its view), I will handle everything there
Create the window only and hook everything in my taskbar controller (which is where the window is created). In this case, the Taskbar controller will become very big.
Pre-create all window controllers and eventually windows too and hide them (when page is ready). Then just show/hide them, so I will have "static" references to all controllers with getController in Application
Which approach should I use?
Edit 1:
I'm trying to dynamically instanciate (and reference it through another controller) a controller. I'm having hard time expecially in referencing it. Any suggestion on how it should be done?
I found Ext's MVC unusable with desktop demo as it's possible to have multiple windows (views) of the same type tied to a single controller. Each window has it's own state and it's hard to differentiate between the views in the controller.
I solved the problem by myself: I preinstanciate the controller as I do with all controllers, by inserting them in Application controllers array. After this, I instanciate the view on that controller when a method is called, then I simply use refs to access this view.
The method is quite clean and using refs feel so good. Obviusly the controller has a method hasWindow which checks if the controller view has been created already.
I am trying to use MVVM light messaging to send a value from one page to another during Navigation (for example, send the id of an item that was selected to an edit page). So the list page's viewmodel sends a message and then sends a navigation message to the view which redirects to the edit page. The edit page's viewmodel gets created only when the navigation to the page happens. So when I register for this event in the edit page viewmodel, I never get the message? What is the best solution for this?
Thanks in advance.
Your best solution would be to use the querystring instead of messaging. If you don't use the querystring, you'll have to deal with situations like the application being deactivated (tomestoned), then the user clicking "back" and your application loads the second page without receiving the message.
However, if you want to continue down this path, you can modify your ViewModelLocator such that your page's ViewModel is created immediately (in ctor for instance) instead of as needed. Since the ViewModelLocator is created as soon as your App.xaml is loaded, you know that any view models will be created immediately. As long as your view model is registering for messages in it's constructor it should receive the message.