I'm looking for an example of a Sencha Touch 2 MVC application that has more than one model, view, controller. I want to see what is the recommended way of witching to a different subject in the application.
For example: Suppose I have an application to manage calls and messages. I will have some welcome screen with a welcome controller and no model, a recent calls model, view, controller, and a messages model, view, controller. My problem is with putting and removing everything I need in the main view port, without allocating elements that are not displayed.
All the examples I found use one controller to rule them all, and a viewport with cards. I was hoping for a better technique. Also from what I saw when I start the application they specify all the models and controllers of the application, but I did not see how it can be used or why it is a good design. I thought that we want to reduce allocations on the phone.
Any pointers to examples or guidelines for how to use several controllers will be greatly appreciated.
I guess you need to go for routing and destroying items then.
VIEW: Welcome -> okBtn press
CONTROLLER: Welcome -> onOkBtnPress -> call route START
Welcome -> deactivate -> destroy Welcome VIEW
START VIEW: view items
START CONTROLLER: route index -> Add new view to Viewport.
Without routing you need to add the new view in the Welcome view, which usually is not preferable.
So you basically call a route onBtnTap and destroy the old view onDeactiveView.
Related
Is it possible to use two ViewModels for a single View at MvvmCross?
The reason is an existing Core library which already has navigation in place and a working app on top of it. Now I need to create another app and leverage the only View for two ViewModels (in core lib there is one view navigated to another using ShowViewModel and I just want to stay at the same view and change my datacontext).
Thank you for any suggestions.
Yes
you can continue to use ShowViewModel and change the way navigation happens by overriding the presenter - see Custom Presenters in the wiki
or you can use a different navigation mechanism entirely - there's nothing forcing you to use ShowViewModel
On the MVC paradigm, a view can only communicate with a controller, and via a blind communication (target-action or delegate/dataSource). I understand that, but is it a violation of MVC if a view communicates with another view, using a delegate?
Almost always. The delegate of the view should never be another view. It should be a controller. The controller is the appropriate place to drive changes in the other view.
A view should almost never say something that another view would care about. A view should say to its delegate things like "I was touched." Why would another view care? It's up to the controller to say "ah, a touch here means that I should move the active focus. I should tell the current active view to let go of focus" (as an example). I view is not responsible for determining what events mean in the broader application, only what events happened, and so are very unlikely to generate messages of interest to other views.
My opinion on this is to use the observer design pattern and simply use notifications (NSNotification)
I am a novice myself. But I would think that it's not. A jsp page when called could just redirect you to anothr jsp page. I have seen that happen sometime. So I guess it is in a way, a view calling another view.
Relevant Data:
I'm making a simple game, using OpenglES. The game itself is done, however I would like to have a main menu as well as some other screens designed in IB. So far I have a death/score screen that is displayed with a simple modelviewcontroller.
I haven't done a ton with GUI building or much programming on the platform outside of C code (posix sockets) and some examples from some books. So I'm not sure how I would go about having lots of views- usually I just use a model view, and it's gotten me along just fine so far. However I don't think that would be the best route here.
Situation:
I have a view controller that shows my main menu- the main menu branches off to the main game, a settings screen, and a high score screen. The main game is made in opengl, and I haven't made the settings view yet, but it likely will be as well. How should I switch between the views? Presenting the main view from the app delegate is as simple as setting the root view controller = newly created view controller, should I do the same thing here? If I do that can I remove the resources from the menu view controller?
Sorry if this is an extremely simple question, I just don't quite get the process.
I'm not entirely sure what you want to do, but an easy way to show a new view controller is:
SecondViewController *aSecondViewController = [[SecondViewController alloc]
initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:aSecondViewController animated:YES];
I hope that helps.
How should I switch between the views?
In the vast majority of cases, you should be using a UINavigationController. Your initial controller would be the main menu. When you want to go into a particular section of your application, you push a new view controller onto the stack. When you want to come back out, you pop it off the stack.
Besides navigation and presenting modally that others have mentioned, another option is to swap out views. May or may not fit your app's flow but wanted to point out another option for you to consider
Best practice for switching iPhone views?
If you are already limiting the game to iOS 5 for some other reason you should look into UIStoryboard. If you don't currently require iOS5 the "simplest" way is to use table views, but that isn't a very "gamey" UI.
I would like to create an utility application that has a navigation based flipside, or "info", view. What would the most efficient way to accomplish this be? I think that i 'simply' need to make a root view controller for the flipside view...but i really only understand that conceptually...not so much how to go about it or, at least, i am not confident that i know how to go about it.
I apologize for the slightly "make my app" nature of this question i have books and books and books...but it shakes out so much differently when i want to make my own project.
You can use a view controller for the flipside view, or you could create / load a view in your app delegate. In the latter case, you can set up the delegate to respond to the info button press, and then set up a transition to the new view which will have a button (which the app delegate also responds to) that transitions back to the previous view.
There is a basic tutorial I found for this here:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/12222-how-do-i-create-uiview-flip-animation.html#post104474
It should be able to at least get you started.
I am creating split view based application for iPad.
I have 1) a root view controller 2) a detail view controller
It is like menu and submenu.
Here I am planning to do. I would like to have navigation in root view controller.
It is recomonded to use or not. If it is recomended how is it possible.
There is a function in the Detail View Controller for showing or not showing the popover Button. Possibly you could adapt that in the App Delegate for the whole Detail View Controller? Just go through the source code provided by Apple. It is all well commented.
Not sure what you're asking. If you're asking whether it's recommended to do it like how you describe, then yes, that's the most recommended way to do it.
Root view controller (the smaller left side menu) usually contains the navigation stuff, while the detail view controller (the bigger right side view) contains all the detailed stuff.
You might want to take a look here for a How-To.
Other documents can be found here.