Re: Basic question on connecting table view to prototype cells
Re: Basic question on connecting table view to prototype cells
- Subject: Re: Basic question on connecting table view to prototype cells
- From: Joachim Kurz <email@hidden>
- Date: Sun, 11 Oct 2015 16:52:54 +0200
> Thank you for the very detailed response! I've now got a navigation controller working in my existing project; I tap a row in the table, and the detail view opens, but now there's a "back" button in the corner. This is just what I was hoping for.
Yes, the „back“ button is automatically provided for you by the navigation controller. :-)
> One other question about this controller. I have a back button in the detail view, but I only connected the navigation controller to the scene where my table is, not to the detail view. I’m pretty sure, based on what I've read, that the "show" segue pushes a new view onto the stack, and because a previous view in that stack is being managed by the nav controller, that new view is automatically managed by it as well.
Correct.
> This leads to the question: say, in my detail view, I have a table, or a button that goes further into my data model. Would that new view, and any other subsequent views, also get back buttons, titles, and other freebees from the nav controller, or do I have to hook something up in Xcode for every level? If one table leads to another table, does that second table need its own nav controller (I’m saying no, but want to check)?
You are right, you only need one navigation controller per stack, even if you go several levels deep. The subsequent views will just be pushed onto the previous ones and the „back“ button will just „pop“ the current view and go back to the preceding one.
You will need a new navigation controller if you „present“ a view controller (e.g. modally), because that will leave the original navigation controller’s „context“.
While we are talking about the back button and other freebies:
The navigation view is the part at the top of the screen, containing the title (in my simple example „Detail“ when the detail view is displayed) a back button and optionally further buttons that can be supplied by the displayed view controller.
You have several options to configure this, but you don’t have to add a back button or title view object to the view controller’s view yourself. All you need to do is tell the navigation controller what should be displayed in the title and possibly on the back button and it will create the appropriate views in the navigation view.
To do that, every view controller can have a navigation item, that provides this data. The navigation item has string properties for the „title“, „back button“ and „prompt. You don’t need to supply a navigation item. If you don’t supply a navigation item (the navigation item does not exist in the storyboard, which is different from a navigation item with an empty title), the following will be used:
- For the title: the title of the displayed view controller. That’s why my example would show „Detail“ in the title, because I set the title of the detail view controller to „title“, even though I didn’t configure the navigation item itself.
- For the back button: The title of the previous view controller, if space is sufficient, or just „Back“ if not. If space is really limited, just the back arrow might be shown. I don’t know whether this limited space affects the voice over description of the back button.
If you do set the „title“ property of the navigation item of a view controller, that will be used instead of the title of the view controller.
The „back button“ property is not used when the view controller is displayed, but only when another view controller is pushed on top of it to supply a description for the back button.
So, consider the following assignment to the navigation items of the root view controller and detail view controller:
rootViewController.navigationItem.title = „Sun“
rootViewController.navigationItem.backButton = „Foo“
detailViewController.navigationItem.title = „Earth“
detailViewController.navigationItem.backButton = „Bar“
When you then tap on a cell and the detail view controller is pushed onto the root view controller, the navigation view’s title would be „Earth“ but the back button would read „Foo“.
(Note that the „backButton“ property does not exist in code, but it does exist as a field to be configured in Interface Builder)
Something else, that you get for free from the navigation controller: You can swipe from the left edge of the screen to go back to the previous screen, instead of tapping the back button. I’m not sure how that works with Voice Over, though. ;-)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden