Passing data through multiple storyboard segues in Xcode - ios

I have a table view which uses a fetchedResultsController to manage a series of 'Venue' objects from core data. When you select one of the rows on the table view, it passes the current Venue object to a new view (via prepareForSegue), which displays details of the Venue object: name, address, images etc. This all works fine.
I have something I want to achieve but I'm not sure the best or most conventional way to do it. I would like the same behaviour as above, but with a map view sandwiched in between the initial table view and the detail view. So the navigation stack looks like this:
table view (showing all Venues) -> map view (showing all Venues) -> detail view (showing one selected Venue)
Presently I have a button from the table view which segues to the map view, passing an array of annotations which are then plotted on the map. The annotations don't contain all the Venue information, they are just assigned a title and subtitle from each Venue. Each annotation shows a detail disclosure button linking to the detail view. However I am conceptually stuck as to how to pass the relevant Venue object (currently only available in my table view) to the detail view when selected from the map view.
My assumption is that I need to do something along these lines: pass all the Venue objects from my table view to my map view, and just have them existing in the background but not being used. Then when a disclosure button is pressed, the map view checks somehow which Venue matches the selected annotation (checking if the title attribute matches perhaps?) and passes that onto the detail view as the 'selected Venue'. However I don't know how best to do this in practice or even if I have the right idea. Is it possible for my annotation to contain the entire related Venue object? Or for the detail view to somehow ask the initial table view for data?
Hope I'm explaining this clearly enough. Sorry its a bit wordy. I'm still fairly new to Xcode and understand that I may be overlooking something very simple, or making a fundamental error somewhere. Any advice would be much appreciated though!

If you only have one selected object, just pass that on to the map view. The map view can use its own fetched results controller to get whatever other data it needs from the data store (presumably the order of importance could be different from the table view).
You could associated the venue objects with the annotations, but it seems that you only specifically need the one venue to pass to the detail view so it should just be stored as an instance variable.

Create a model where you query a venue by its name/id or something. Then when you go in the last detail view pass the venue name/id to it from the map view.
Or, as you are suggesting in your question, pass the whole venue object to your map view, use whatever you want from this object in this view and when you segue to the detail view pass the whole object again.

you post your data therw -prepareForSegue check the below post
How to pass prepareForSegue: an object
and you can check the below storyboard example
https://github.com/pandamonia/A2StoryboardSegueContext

Related

correct use of mvc principle between a view controller to a table view

I'm building a todo app, and I want to create a "History" page in the app.
Right now I have a model file and I created in it a "todo" entity with some different attributes (body, status , time etc), and im using core data to holds those todo's.
So I created a button to the "History" page which is a table view, and Now im trying to figure out how to keep the todo's that was marked done and populate the History page (table view) cells with this todo's.
So I thought that in the Home view controller I will create an NSMutableArray property called "todos", And ill create a method in the Home view controller .m file that is adding todos to the todos property, import the home view controller to the history table view controller and populate it's cells with the todos array property.
How bad is this solution?
thanks
You should not be using an array to hold your todos. This could potentially result in excessive memory use and performance degradation. To display Core Data entities in a table view, use the NSFetchedResultsController class which was specifically designed for this purpose.
You can find boilerplate code from the Xcode template (choose Master-Detail, check "Core Data" and look at the master view controller).
In your lazy initiator of the fetched results controller, add this predicate:
request.predicate = [NSPredicate predicateWithFormat:#"done = YES"];
or instead of done use whatever flag you have included in your model to indicate that an item should be shown in the history view.

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.

iOS: Property of managed objects relationship has changed, but managed object doesn't notice

I wasn't able to find anything on this except the fetched results controller problems, which I already solved as well.
But here I have this problem:
My view controller (let's call it MyVC_A) has a property PointOfInterest *poi. This entitiy PointOfInterest has a relationship to the entity Category, called "belongsToCategory" and is n-1. So a PointOfInterest only belongs to one category. So if you select one table cell in MyVC_A which represents one PointOfInterest, you get the next view controller showing all available categories. If you change now the selection of the category and pop this view controller back, the belongsToCategory attribute in MyVC_A hasn't changed, even when I put all the label and image code into the viewWillAppear method.
So I know the property has changed and has been correctly saved in the context, but no changes are displayed. I kinda know why, but what can I do against it? How can I "refresh" my PointOfInterest object in MyVC_A to display the changes?
You need to call performFetch: on your fetched results controller and then reloadData on your tableview.

How to show a list of items without a tableview which changes when the input changes

i know that the question sounds weird but i couldn't find a better way to put it or any solution online or with my current knowledge. I currently use a view controller + a table view where user enters a list of elements to filter my database (core data) and when he clicked the search button i fill tableview with filteredContent.
Now the question is this.
how can i show this filtered content simultaneously in the same viewController where user enter the input?
Is it possible? If yes how?
Assuming the user enters the filter via text field, make the view controller the text field's delegate and implement shouldChangeCharactersInRange:.
Each time the input changes, apply the search as if the search button was pressed.
But it seems the real question is how to do this without a vc transition. The answer is either convert to an NSFetchedResultsController, which does this kind of thing for a living, or do it yourself via the table view datasource methods.
If the latter, you'd keep an array that holds filtered search results. As the user enters search terms, you search core data, place the results in that array, then reload the table view. The datasource methods base their answers (numberOfRows, cellForRow, etc) on that array of filtered results.

How could I drag a tableview from up to down and fire an action then?

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

Resources