Not sure I'm designing this correctly (guidence is appreciated!), but I have a search view which is called from many places. Search screen has has it's own ViewModel. When a user selects something from the search screen (after searching :), I need to send the selection to whatever view requested the search to take place (search screen is a pop-up).
I have a view locator that pops up the screen screen when I send it a message. The message is sent from a ViewModel (MVVM Light) to the view locator.
Do I register a call back? Broadcast a message? Set a Property? Dynamically Bind the "Select" button on the search screen back to the view model that initiated the call?
mmmm so many questions, so little time...
Regards,
Richard
I am not sure if MVVM Light has anything equivalent to an EventAggregator, but this is the best way I can think of for you to broadcast this event.
Another option would be to use the Reactive Extensions (Rx) and make the receiver subscribe to the event using a filter before you open the search view, then pass the filter to the search view so that the actual operation is called using that filter, so even when the search view model requested the search is the other view model that will receive the event.
I had a similar issue and here is how I did it.
I had a difference ViewModel for my Pop Up window and the view model took a parameter of the object you want to return e.g. You have you MainViewModel and a property Customer. In the PopupViewModel constructor I passed the Customer from MainViewModel. When I did my search and found the Customer you are looking for, assign that customer to the Customer reference from MainViewModel. Assuming you have implemented INotifyPropertyChange interface, it will show up in your main screen as soon as you select a customer. Let me know if you understand or I will post you an example.
Hope this helps.
I recommend that you pass the reference to the interface element making the call forward to your search. All of this is taking place at the view-model layer as far as I can tell.
The other option is to set a flag in the search result or search object that registers which interface made the call. I'm not sure how you would go about making a callback in this case.
Related
I am new to programming iOS and I am not sure on how to implement multiple/relational drop down pickers into my design.
I have a search form in my app that works like a panel-menu. If you click on the search icon then the panel slides in with the search form.
But what is the best way to implement multiple/relational drop down pickers for my search form?
The pickers are relational. First you select a state then you must select a city. Once you selected a state in dropdown1 then dropdown2 should get populated depending on what you selected in dropdown1.
So is there any good solution for this when it comes to design?
I would like to show both pickers at all time. Kinda like a datepicker when year / month / day always is shown.
But if anyone has a good resource example on relational pickers please share.
Thanks in advance,
You can set this up with nested UITableViewControllers.
These types of projects are generally called Master/Detail.
The Master tableView would display the list of categories.
Once the user has selected a category, the specific category is passed to the detail View controller. It queries all the subcategories for that category.
This can all by done in Storyboard, using Auto Layout, self-sizing cells, and a combination of show and unwind segues.
A show segue pushes a (table) view controller onto the navigation controller stack. In your case, the category controller would push a subcategory controller. prepareForSegue:sender: is where the category controller would provide the category to the subcategory controller.
An unwind segue returns from a view controller, popping it off the navigation stack. In your case, the subcategory controller would return (with the selected subcategory information) to the category controller, or a previous view controller.
It may sound like a lot to digest, but if you read up on recent (i.e. for iOS 8) walkthroughs which use these concepts, you'll have learned some acceptable practices for how information and control should flow within an app.
There's one more thing I didn't mention, called Core Data. Core Data, and NSFetchedResultsController would be a great tool to learn and use for the app. It's probably more complex than anything I previously mentioned, but once you get a handle on it, you will really appreciate it, and may end up using it in many apps!
Don't get too bogged down with how your app should look. Focus on how the model and view controllers are written, and get a good understanding of the underlying frameworks. That's more important right now, than any fancy transition/animation.
The design of any app will evolve as you use it. You'll discover what works well, and what doesn't, so don't get too attached to any one way of organizing the data!
Hope that helps! Enjoy programming for iOS, it's a great platform!
I have an app that has a containerView that changes its view based on the clicking of one of three different tabs. Each tab contains different pieces of contract data.
It's now come the time for me to get ALL of the data from those tabs but I'm not sure the best method. Delegation is 1:1 and therefore I don't think would work as I can't be sure that each tab has been loaded. Same goes for the NotificationCenter as each has to register as an observer.
I've considered iterating through each and passing the message "view", this will verify each has been loaded, then firing off a Notification or while inside of each view calling a method to get me the data I need so that I'll end up with one large dictionary of values.
Any other ideas or commentary on my possible solution?
Let me know if more details are needed, this was a poor design from the start but I was required to implement it like this as the clients had approved the design BEFORE I started at this company and it took them several weeks to approve anything.
I've solved the issue of every subchild not being visible by calling [subviewName view] to assure that viewDidLoad was fired. Inside viewDidLoad I register for the notification, now I've assured that each view can create a dictionary and pass back it's information to the parent.
I have in mind following behaviour for my table view controller. It is a table view to show to do items, just like a tasks list. I want to know if it where possible to drag down the whole table view and hold it in this position, and while in this position the user could enter a voice command that should be stored as a sound file in a core data entity.
Any proposals and help is welcome.
There is a project that implement PullRefresh, but you can use this to do another stuff.
Take a look to EGOTableViewPullRefresh
I have an app that requires that a menu changes in view controller 1 when a button in view controller 2 is pressed. What is the best way to achieve this?
I've heard a lot of talk about NSNotification but I thought that was for displaying alerts?
The "right" way to do this is to write the new state into the app's data model. When another view controller becomes active, it should update its view according to what the model says. That way, the information will be available to other view controllers even if they don't exist when the user makes the change.
Notifications are a great way to convey information to other objects without having to know about them specifically, but a notification is only effective if the objects that care about it exist at the time that it's sent.
You're thinking about this in the wrong way. One view controller shouldn't care about what happens in another view controller.
If a button being tapped results in changes to the contents of a menu, it sounds like you're changing the data. The button press should tell the model layer that the available options have changed, and the other view controller should load the available options into the menu from the model layer.
I've heard a lot of talk about NSNotification but I thought that was for displaying alerts?
No, it is for distributing information about events to the rest of your application in a way that doesn't couple those parts together. It's not about interacting with the user.
NSNotification is one way to do it and no, it has nothing to do with alerts.
It works like this: a "producer" can post (send) a notification. Other objects can subscribe to notifications and react to the notification. It's an excellent way to decouple objects (the goal is often to make each object know as few information about the other as possible).
Search for NSNotification tutorial, there are quite a few. You should really get familiar with them, they are used a lot on iOS and Mac OS X development as they are very, very handy.
If you're not presenting both viewcontrollers at same time and you transition from viewcontroller1 to viewcontroller2 you could use segues to pass information from vc1 to vc2. I think notifications are great but i think isn't necessary.
having a bit of panic and really really need some help with this!
I'm making an app to fill in forms. The layout of the forms are created on a web server, and then the ipad app syncs with it, copies the form database, and then runs it locally.
One type of text field is a UITextView where the user can input text either by writing directly to the field, or by using one of many pre-defined texts (also defined on the web server).
To use a pre-defined text, the user touches/selects the tablecell that is containing the UITextView, and then a category-picker-view is pushed on the screen. On selection of category, the user gets a list of texts, and upon selection of text, the user gets a simple uitextview to edit it before insert. With a save button, the user then gets moved back to the original view where the chosen text is now added.
Flowchart:
root view with input fields-> category picker -> text picker -> editor
/\ |
'------------------------------save text------------------------'
The problem is that when any other view loads, all other input fields are emptied! The value of the selected field is passed via prepareForSegue, so that one is kept.
I have a save function which saves all fields to the database. I tried to put a call for it inside the prepareforsegue call, but it either crashes or does nothing.
Question: Where could i put the save function? Could/should I do it another way? Thought about putting all tag's values in a dictionary inside my appDelegate instead of running the save-function, but how could i update it every time an input field is edited?
Also - would putting the categorypicker etc in some kind of popover/modal/popup-view instead of the push segue prevent the values from clearing? I've got no experience from such views, could someone give a good starting point? (perhaps a good tutorial rather than heavy apple docs :)
I have a deadline for this tomorrow, with LOADS of more things to complete as well, so I'm very very grateful for ANY help!!
Thank you for your time!!
/Dave
I think your problem is caused by an absence of a model (in terms of the model-view-controller pattern). A model that represents your form data (e.g., custom object, NSArray, NSDictionary) should be updating the view and should be passed in prepareForSegue, not an input field's value.
Specifically, create a new property that maintains the latest data. When the user makes an edit or selects a category for some field, update the model. Then, when you return to your form view controller, use viewDidAppear to update the input fields to their latest values.