Maintaining information between viewcontrollers - ios

I am pretty new to stackoverflow so please let me know if there's anything I should add or leave out in my posts from now on.
problem:
I have one original view controller that has a tableview on it with 2 options, "Date" and "hairstyle" the user is able to click on one of these table cells and it brings them to a new view controller where they can select a hairstyle/date. When they click done, they're chosen date/style reflects on the original view controller. The problem is, that it won't reflect both choices at once. Whenever you try to reflect one, the information from the other is reset for some reason.
Feel free to let me know if there is any more information you would like me to share in this post. Thanks for all the help.

Whenever your detail view controllers are about to pop back to the original view controller you can send the data using prepareForSegue.
In order to give you more detailed info we need more details about how you are doing things.

Eagle11 is right you need to use prepareForSegue, before jumping to code you better check this very useful(for me) links:
Passing Data between View Controllers
iphonedevsdk (my personal favourite)
Storyboard tutorial
Passing Data Between VC
Some issues:
passing data between views

Related

Passing data to Detail View, actual data or reference ID

Situation
Let’s say there is an iPhone app that shows articles. Articles are loaded from a server.
It has two views.
TableView: Shows list of articles
DetailView: Shows detail of selected article
Problem / Question
I want to know better way of passing data from TableView to Detail View.
Which one of the following is a better practice?
Option 1
Pass an actual Article object from TableView to DetailView
DetailView just displays the Article
Option 2
Pass reference ID of Article from TableView to DetailView
This case, the DetailView loads the article from server by the ID of the Article.
Option2 seems a better design since relation between TableView and DetailView is minimum.
Option1 seems a little bit faster since i doesn’t have to connect to API ever time it loads an article
I understand it depends on situation but i would like to know if there is any reasonable guideline.
You should use a combo of both since many apps such as Facebook also do the same. For eg. if I have a photo that has likes in my notification bar, I can click on that photo and see it even if I do not have an active connection at that time. I will obviously be shown the older data. However at that time, Facebook immediately sends a call to the server and the updated likes are shown.
Therefore it should be ideal to pass the entire object to the next VC and immediately send an async call to the server. Any changes should then be reloaded in your complete data model. Hope this helps :)

Swift iOS solution for multiple/relational drop down pickers

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!

Link a UiLabel with more than one answer

maybe im not asking the right question, or maybe is not what i really need but the thing is in my app I have 2 Viewcontrollers, the first one with a picker view where you can find cities, you chose one and then you press a button that takes you to the second view controller, there you have and other picker view that shows you places according to what city you had chosen, but my problem is that I have a Label (in the second controller) that should show what you choose, so i think i must use different 'ifs' according to the place you have chosen, but it has to depend also on what did you chose on the first view controller and there is my problem, i don't know how to go forward with this.
Hope someone has an answer for that.
Im using Swift.
Sounds to me like you're using a master/detail design. On the first view controller you pick a city. That sends information about the selected city to the second view controller.
In the second view controller you'll look up the data to display for the selected city, and use that city-specific info to populate a picker (and anything else you need.)
You can either store your data for all cities in a global model and simply pass a city index to the second view controller, or you can have the first view controller "peel off" the data for the user's selected city and pass that data to the second view controller.

How make a viewmodel return data to another?

I'm trying to find a solution to passing back data from a viewmodel to another when I call DoClose()
I've got a view where the user can add informations in edittext, there is also a button that open a new view where the user can enter others informations. Then he need to go back (DoClose()) to the first view and there click on the button to save informations.
I tried to make a RequestNavigate<> but it create a new view in stack.
I don't know how can I get back the informations from the second view.
Someone can help me ?
This article from #gshackles gives one mechanism for doing this - http://www.gregshackles.com/2012/11/returning-results-from-view-models-in-mvvmcross/

When I transfer from my master view to my detail view after adding a new item, my detail view is empty

I'm making a sample app to learn iOS dev, and I have the app create default items to populate the tableview originally, and you can add further ones as well.
If I tap on the default ones (well, there's only one) and segue to the detail view it shows all the details (Name, Location and Date) as intended. But if I add a new one, it comes up with those fields being Empty.
I can't figure out why. I have seemingly all the view refreshing methods set, and it should be setting the detail view's data object which then feeds the labels.
Could anyone help? I'd supply further code if requested, I just don't know what to supply now as I'm not sure exactly where the problem is. It's a rather simple app, though.
Project available here: http://cl.ly/3N0o272M3y1K
Ok this took a bit longer than planned - but it is a good way to learn.
I have attached the project in a zip file.
The code is a bit different then what you posted, but if you compare them side by side, you will see how they are planned and build differently.
It shows the Segue working within the Storyboard.
There where 2 big problems with your project outside of your misuses of the methods.
You need something like Core Data if you want your data to be persistant. In the example I have given you I have used Plist, this will do the trick, but is not persistant in this case.
Also your detailViewController had no labels for the text to appear, so you will need to look into Custom Cells for that - to match your design.
Good Luck and I hope this is useful:-)
Updated Project

Resources