So, I have a view container in my iPad app. Based on a selection the user makes, the view in the container needs to change. How is this done? Can I link several view controllers to the same container in Interface builder and then just trigger the segue to get them to change?
I haven't find correct solution for this problem, but have a look at this link.
What it basically does is creating in-between view controller which is triggered with embed segue. And this view controller is then connected with custom segues to destination view controllers and is responsible for presenting them.
So the answer is that you can not link several view controllers to the same container in Interface builder and then just trigger the segue to get them to change. But this is closest workaround that I have found.
Related
I believe that the best way to communicate between controllers is to use a service to store a message.
I am currently building a master-detail application and would like to use a service to store the list item that has been clicked in the master so that I know which element to fetch in the detail.
So as I understand it the chain of events should be like this:
User clicks on button in the master view.
Service updates local variable with the button that was clicked. The service then uses $broadcast to broadcast to the detail that the variable was changed.
Detail has a $on that then reacts to the button being clicked.
Does this flow make sense?
And can someone point me to a tutorial on how to implement this in typescript?
Thanks
I am new to Metoer and I have two dumb questions related to the meteor collection and the subscribe.
1) I understand that if I subscribed to a collection in one of my controllers, and it will load the data into my local collection and be persistent until I stop the subscription. my question is what if I have different views which need to access the same collection but the views are independent of each other which means, user can access any of the views without accessing the others first.
For example, if I have view to display all parties hosted by current user and all parties hosted by other users. What is the best way to subscribe it? I originally thought I can just subscribe in one controller to get all documents and do the filtering in the collection selector. But this won't work as user can access any of the views first. so I ended up subscribe to it in the two controllers. Is this the right thing to do?
$meteor.subscribe('parties').then(function(){
....
});
$scope.parties= $meteor.collection(function(){
return Parties.find({// select either my parties or others' parties});
});
2) My second question is that if I have a list view and a details view, I am trying to access the object in the details view's controller.
$scope.party = $meteor.object(Parties, $stateParams.partyId);
This works fine if I click the details button from the list view as the list view's controller has subscribed to all the documents.
However if user refresh the page from browser (which is not intended in a meteor app but we cannot stop users from doing that )? the object won't be accessible.
How can we deal with this in a Meteor app? I don't want to subscribe it again in details view even that will solve the problem.
I don't know if prevent the controller from reloading is exactly what I need.
I have the following scenario:
A view called client.list.html and it's controller ClientListController (list clients).
A view called client.html and it's controller ClientController (create and edit client)
On the client list, there's a button to edit the clients and some pagination.
What I want to do is:
When the user clicks to edit the client and go back to the list, the information (like selected client, current page and results) should be there still. But the controller gets reloaded and everything is lost.
As of my understanding you want to let the data binded to the view still there, correct me if this is wrong.
I had a similar problem where I had to keep the certain data on the view once loaded even if the view is reloaded. In this case you can bind the data to the view through $rootscope. There is only one $rootscope for the application and will not reload even if the view is reloaded.
Getting started with Angular, I am trying to implement a toolbar.
The application is structured in a menu bar, a view and the toolbar that form the web-page.
This toolbar has a general purpose (provides help functionality and error display), but for specific views adds some buttons that control the functionality (save, cancel, edit, delete, etc).
In the current design the view and the toolbar are siblings. The view controller depends on the data the view contains, and it can have different functionality. (For example: A view might allow data import, so there will be an import function in the toolbar, while other view might not.)
My problem is I cannot picture the structure of the communication between the view and the toolbar. Because the controllers are tightly coupled a service does not seem to address the communication.
Any help?
You can:
Share data between different controllers/services using rootScope
(use wisely)
You can Publish and Subscribe for app events using
$on, $broadcast and $emit
One good strategy which I have used and helped is to keep all App events definition in one service called something like AppEvents so you can easily keep track of them and control what event causes what from a single place.
Here is one nice article to read that expands more on this topic
I'm trying to port the code from existing backbone to backbone.Marionette application. Refer the following url for application that i have started.
http://www.adobe.com/devnet/html5/articles/backbone-cellar-pt1.html
According to my code structure,
I have 2 views in my code.
ItemView with a form
Composite View that contains list of itemViews for each li tags.
Initially on page load, it renders the data from db using fetch() call and appends all wine names to side bar. Then, on each wine name click, I can view its corresponding details.
My doubt is that, Everything works except listener from form itemView to CompositeView. I'll explain it in brief.
When i update/delete in the form ItemView, the particular li in CompositeView is not updated/deleted by listening to the event binder. It works if i use localstorage but not as server/db based app.
What should i do for listener to listen changes from form itemView and render it. Any suggestions would help me to continue furthur.
When using a Marionette CompositeView, the rerendering will be done for you. You do NOT need to add a listener to the model or collection, because Marionette automatically listens to those events.
If this doesn't solve your issue, put your code on jsfiddle so we have a functional example of the non-working code.
Edit based on jsFiddle :
I've added code that should make your example functional (hard to determine without a functional example) : http://jsfiddle.net/VvXDs/ Basically, I added an app-level message, and listen for it it the list to trigger render if necessary. Although this is functional, this pattern is bound to cause problems.
The main thing that is making your life more complicated, is the fact that you're managing the routing as if the application were stateless web app (more on that here http://lostechies.com/derickbailey/2011/08/03/stop-using-backbone-as-if-it-were-a-stateless-web-server/).
What's happening is that you have a collection with all of your chocolate, and a user clicks on a link to display one of them. Then, although you already have the data, you fetch a new instance of the model to display from the server. So obviously, the listener won't work: they're defined on 2 different instances (client side) of the same model (server side). (If you're worried about stale data, you should instead pass the same model instance to the view, and call fetch on that instance to update the data.)
A better design approach is to use the same client side model instance in both your menu and the form view. Then, when the model changes, the menu line item will automatically get updated (because they're using the same model instance, so the "change" event listener will word properly).
If you're interested in learning more about using routing in a stateful manner, take a look at the free sample to my book http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf (chapter "Implementing routing").
Remember: the code I added should work, but the design will probable make your development more challenging...