From a Modal Controller to a Detail VC of a Master VC, with proper back button (Contacts.app style) - ios

I'm currently implementing an app really close to the native Contacts app. The app consists of:
A Master View listing items
A Detail View showing the selected item details
An add button to add an item which:
Allows to take a picture if the camera is available then go to the input view (a form basically). The camera is presented modally.
Directly goes to the input view (the form) is no camera or no authorization. The input view is presented modally.
The QUESTION
When the user presses the OK button after filling the form in the Input View, how can I jump to the Detail View, with the Back Button of the Detail View pointing towards the Master View (and not the Input View where the user comes from) ?
This is exactly the behavior of the native Contacts app, when you add a contact and press OK, you land on the Detail View with the back button leading to the list of contacts.
Here is how my storyboard looks like:
I searched a lot for a solution, but nothing good sor far...
Thank you in advance for the help.

MasterViewController is a NavigationController.
DetailViewController is a ChildViewController of MasterViewController
CreationViewController is presented modally from MasterViewController
You need to provide delegate for the MasterViewController to know the CreationViewController have finished the creation flow and the created info. Then you dismiss the CreationViewController in MasterViewController. Finally, you push DetailViewController with the created info.

Related

UITabBarController - transition from one tab's navigation stack to a view controller of another tab's navigation stack

Novice iOS developer here. I am making a simple tabbed chat application in Swift using a UITabBarController. For simplicity, let's assume the application only has two tabs, "Contacts" and "Chats". Each of the two tabs has a navigation controller.
The "Chats" navigation stack begins with a UITableViewController called "ChatsTableViewController" which lists the user's chats. When the user selects a chat, the app segues to a MessagesViewController which displays the messages for the selected chat.
The "Contacts" navigation stack includes a UITableViewController which lists the user's contacts. Upon selecting a contact, another view controller is presented modally, asking the user whether they would like to begin a chat with the selected contact, and giving them the option to cancel. If the user chooses to begin a chat, I would like to transition from this modal view controller to the MessagesViewController of the "Chats" tab, passing the information necessary to display the chat (which I have at the ready in the modal view controller).
When the MessagesViewController loads, regardless of whether we get to it by selecting a chat from the "Chats" tab or by creating a new chat from the "Contacts" tab, it should have a navigation bar at the top with a "Back" button that takes the user to the ChatsTableViewController.
I have done a good deal of searching, but have not found any solutions that fit what I need. Any suggestions would be greatly appreciated! Here is a summary of what I am looking for.
Standard way to perform a transition from a view controller in one tab's navigation stack to a view controller (that is not the root view controller in my case) of another tab's navigation stack, while passing relevant information to display in the destination view controller.
The view controller I transition to should have a navigation bar with a back button that takes the user to the previous view controller in its navigation stack, just as if they had accessed it from the normal navigation flow of the tab.
EDIT: I've found that you can easily switch tabs programmatically using self.tabBarController?.selectedIndex = index_of_tab_to_switch_to, however, this takes me to the first view of the tab and I am still unsure of how I can pass data. Any thoughts on how I can proceed?

Use case for push versus modal segues?

Let's say, I have a scene (pushed view controller with a navigation bar), which displays some tabular data in a table view.
In the navigation bar of that scene I have a + sign, which should open a new scene, where the user can add a new item (row to a core data table).
In the table view, each row has an arrow on the right side of each cell, which opens a scene where the user can edit that particular item's details.
Should I use a push or modal segue for the +?
Should I use a push or modal segue for the arrow?
What is the "best practise"?
I understand the difference between push and modal segues, but I want to know which is better suited for the above use cases.
If you want to follow Apple's best practices, I would suggest the following :
For the "Add" functionality, use a modal segue.
For example look at the contacts app. Pressing + shows a modal view controller.
What's the logic ? for start, modal view controllers usually have a "cancel" button, as opposed to the "back" button on a pushed vc.
When the user presses "back" - he'd expect a way to come back to the vc. Usually "back" saves your data on iOS (auto-saved).
So by using a modal segue you force the user to submit the form , or cancel. The modal presentation hints that you really need to fill this screen.
For editing - push. but modal could work as well (and you could reuse the same VC).
Reasons for push :
you get a hierarchy of vc's , going back and forward while drilling down.
(you should implement) auto saving when going back (just like other iOS apps)
For adding a new entity to the core data table, on tapping the + button (I assume its a right bar bar button item on the navigation bar), use the modal segue.
The view for adding a new row for the enity has to be presented modally and once the save is completed, dismiss the modal view and reload the table view to display the newly added item.
Also for displaying the details of an entity row, use the push segue. A user expects a push action when he selects a table cell and it is the ideal way to do that.
I hope this quick summary will help you :
When you want to show a detail view of a summary view, use a navigation controller and Push Segues. If the "parent" view doesn't really relate as far as data is concerned to the "child" view, then use a modal. A good example for a modal view would be any entry view. This view doesn't really have any relationship as far as data is concerned to the "parent" view., the entry screen will just take data dat from user & will save & can go away & giving control back to parent

Data disappears when switching between view controllers

I am writing an iPhone application using the storyboards for an initial mockup. The problem I have right now is switching view controllers.
I have a table view controller and another view controller. All I want to do is use a back button to go back to the original screen, and I can do that, except the data disappears. The storyboard that I have is shown below.
I have the Back button going back to the original navigation controller. I have also had it going back to the Card view controller.
I have hard coded some example cells to just see how things look and they show up just fine when I run the simulation. When I click the back button though, it goes back to the All Cards screen and the cells that were there are now gone.
If I need to post some code just ask for what part would be helpful, I have done all of this through storyboards though.
I'm sure it's something stupid I've done, any point in the right direction would be greatly appreciated.
Basically: you pushed where you should have popped.
What you are seeing on the Storyboard does not exist yet. By segue-waying during runtime to a view controller it gets instantiated.
When you segue-wayed during runtime from the Add Card view controller "back" to the Card View Controller - here is what happened: instead of popping the navigation stack all the way back to the Card View Controller you already had, you just instantiated a new Card View Controller and pushed it onto the navigation stack. You could verify that by going all the way back to the original Card View Controller by tapping the back button several times.
What you could do to accomplish your task is this:
Instead of using the Storyboard for your back button use an IBAction in code:
- (IBAction)popToRoot:(id)sender {
[self.navigationController popToRootViewControllerAnimated:YES];
}

displaying UIPickerView over current ViewController xcode

Here is my current problem. I have a UIViewController setup with its data and everything on a small sized view controller. What I am trying to see is if it is possible to connect that to a separate view controller. For example I have a view controller that has a user click a button. Upon pressing the button the UIPicker ViewController would pop up from the bottom and I could go from there. I know how to enable this if the picker is on the same view controller. However, I have no idea how to if its on its own ViewController. Any ideas?
One way to do this would be to put the picker view on the same view controller and make it hidden, and, when they press the button, unhide it or load the other view controller when they press the button; this will display the other view controller, not what's on the current one.

adding a view to UISplitViewController in Storyboard, Xcode

in my application i have a UISplitView, but before this gets loaded I need to display a page where the user enters some details and then clicks okay to display the spitView. I have tried dragging a view controller from the object library on the right but this gives problems. Please advise me on the right way to approach what I'm trying to do,
Thank you
I would have the splitview present the viewController that collects the user data. Present it modally then dismiss it after they enter the data and the split view will be there for you.

Resources