Just after a bit of advice really and a push in the right direction.
I have a modal view with a navigation controller containing 3 levels (views):
My Active Jobs (pulls a list of the users active jobs from the server and displays as a table, select a job and view 2 is passed the jobID and displayed).
Job Details (pulls the job details and a list of its updates based on the jobID from the server, select an update and view 3 is passed the updateID and displayed).
Update Details (pulls the details of the update based on the updateID from the server and any photos attached to that update, select a photo and it displays full screen.
So I have a seperate modal view in a different part of the app which displays the latest updates to the jobs. This includes new jobs assigned to the user and new updates for active jobs.
What I would like to do is link directly to the relevant view in the navigation controller when an item is selected in the latest updates modal window.
So my thoughts are to call the the Active jobs modal view when a latest update is selected and pass the relevant ID(s), initialise the combination of views needed in the stack pass the ID(s) to the views then initialise the navigation controller with the setViewControllers:animated: method.
Is this the best way to do it, or is there a better way?
Any help or suggestions would be greatly appreciated.
I don't see a reason to duplicate the functionality of creating the views for the view controller. One thing you could do is have a "cache" for each element (jobId and updateId ). If you want to push multiple viewControllers at once you would fill the cache with the desired values. Then when you push a viewController onto the navigationController, the new controller would check the cache and if there is something cached you would simply push the next view controller directly. This would all happen quickly and should be unnoticeable to the user.
By doing it this way, you are using the same code regardless of if you know the next id or not. You are either using the user selected id, or the one already predefined by the other selection.
Related
I'm building an app which has 4 screens, on the second screen the user will set time by date-picker on tableview.
There are few times to be set (depending on array.count).
On the third screen the user will set the location, and on the 4th screen user will see info from API and the time has been set by the user, also on tableview cells.
In case the user wants to change or update the time he set in one of the cells to different time, I need to be able to go back to the second view with all the input user added already remain, and the user can change only the cells they want to change, without adding all the time all over again.
When I'm using segue it creates a new 2nd vc and all the previous info erased.
I thing you have to use delegate to propagate this information from whichever screen to which ever screen you want. In Order to achieve that you have to loose the segue.
https://medium.com/#nimjea/delegation-pattern-in-swift-4-2-f6aca61f4bf5
In this link Delegation pattern is explained very well. Please refer that.
I have a customer view controller that is a subclass of UITableViewController. It has a list that lists all the customers. I have a + button in the top right. I want to make it so when people click the + it will go to the add customer screen and after you click save it will act JUST like the iphone contacts list and then display the newly added customer.
Would I need to create a controller for each view? One to display the list, one to add the person and one to view the contact then another to edit the contact? Or should I use one controller and just add a bunch of views in IB into the single view controller?
Create a CustomerListController for seeing ALL customers.
Create a CustomerViewController for viewing and editing the detail.
Subclass the CustomerViewController calling it CustomerAddController for creating, as this will need a little more functionality.
Core Data Recipes application will give you some good pointers around this.
If you want it to only create the record after you hit save, you'll need to:
Create an additional NSManagedObjectContext, assuming you're using Core Data.
Pass that context to the instance of the CustomerAddController class only (not needed for the view class).
When the Save button is hit, you'll need to merge the two NSManagedObjectContext classes in the CustomerListController.
I believe the way the Contacts app does it is:
Contacts list is a UITableViewController in a UINavigationController
Touching the + modally presents (from the navigation controller) a different view controller for adding the contact
Touching Done pushes a new view controller onto the navigation controller for viewing the newly created contact, but it isn't visible yet because the modally presented contact adding view controller is on top. Immediately afterwards, the modal view controller is dismissed, revealing the newly created contact.
To answer your question, I'd suggest using three different view controllers, just like the Contacts app.
I suggest you to use different views for every task because using one IB file uses more memory where as if you use different IBs and view controllers for every task then there is not too much memory is used and after completing one task for example when you save the user detail free the memory for that view so that you app do not use much memory.
In my specific example I have a navigation controller inside tab 2 of a tab bar controller, the root navigation controller view has three buttons:
'nearest store' - this pushes a view that contains a mapview with nearest stores, clicking the store pins will push the store details view.
'all stores' - this pushes a view that contains a tableview that lists all the stores, clicking on a row will push the store details view.
'store search' - this pushes a view that contains a text box which allows a town/postcode search for nearest stores which appear in a tableview, clicking on a row will push the store details view.
The issue I have is how should the store details view be implemented since it will be pushed onto from multiple parent views.
I currently have each parent view, nearest store view, all stores view, store search view, contain a seperate instance of the store details view controller which is allocated memory and pushed onto the view controller as necessary. My worry is that if I access the store details view through each of these 3 paths then there will be 3 copies of the store details in memory since I am not sure when these will be automatically released.
My thinking was that an alternative way of implementing this is to have an instance of the store details view controller from the primary navigation root controller with the three buttons.
From any of the nearest store, all store, store search views, if the store details view needs to be accessed then the current view is popped off the navigation controller and a method in the root controller will be run to push the store details view on. This will mean that there will only ever be one instance of the store details view in memory since it will be reused everytime it is accessed.
Since the popping and pushing to get to the store details view will not be animated, it may be confusing for the user when they click the back button as they will end up on the root view controller and not the view they were previously on.
Is this a good way to implement this view structure? I am not sure I understand how the iPhone keeps views in memory and if going down this alternate route will be beneficial or a waste of time.
Thanks for any help.
What I would do (may not be right) is have a tab bar controller and the three different store search views under each of the tabs.
Then have a singleton view object which will be your details view. Therefore all three of the views can access the same details view object.
Hope I kinda helped :S
I have a table view that contains a list of Project objects. When an item is selected it brings up a detail view. Pretty standard. What is the best way to implement "add" functionality (popup a modal view controller to input new values and save the item)?
Currently I have view controllers for my root view, detail view, and add view. Essentially the detail view and add view are exactly the same except for a save & cancel button in the add view. Is it possible to reuse the detail view in the add view?
Finally, what is the best way to display the list of project properties in a grouped table view separated into sections?
Thank you for your responses.
Most likely, you are already passing your detail view controller a managed object that it is supposed to display when in detail view mode. When the user decides to add a new project, just create a blank object, pass it to the detail controller and display it. (You might want to insert this blank object into another "empty" managed object context in case the user cancels the add process to avoid having to clean up your main managed object context in that case.)
The detail view controller would also need a flag that tells it whether it is in edit or add mode so it can adjust its controls (and possibly delegate messages it sends to its owner) accordingly. You would set the flag to the appropriate value before you display the controller.
It sounds like you're looking for a UINavigationController. The UINavigationController lets you push new view controllers on top of existing ones. It gives you a navigation bar at the top that will allow the user to go back to the root controller. I think it's the kind of controller Apple uses it in the default email application, to give you an example.
Concerning organization: you design your root view controller and a detail/add view controller. In your app delegate, you attach a UINavigationController to the window and you set its root controller to the main controller you want to display. That root controller can then push the add/detail controller onto the stack (and when it does so, it can tell the add/detail controller which types of button to display.)
I can't answer your grouped properties question, but it sounds like a separate question anyway.
I have the following set up in a navigation controller.
The root is a list of categories (banks, hotels etc) and each category has a child view below it containing a table view of items (Bank A, Bank B etc). When i select 'Banks' i see my banks (list coming from from web service), but then i go up one level to my root, and select 'Hotels', when the view loads (from web service), i still see my banks, for about 1 second, before the view is updated with the list of hotels.
How can i stop the previous category's list showing up when i choose a different category?
Thanks
Clear the array first before you load the view, try also getting views to reload