[MUSIC] Hello again. In this lecture we're going to talk about the tab view controller. The tab view controller, like the navigation controller, is very commonly used in iOS. And you can see it all over the place. In fact, they're often used together still a navigation view controller inside a tab view controller is a very common thing that I'll show you in a bit. You can see the tab view controller in iOS in the app store, iTunes. On the simulator, I believe the Health App, yes as you can see has these tabs at the bottom. And this is a tab view controller. And like the navigation controller, it doesn't have any UI itself, and exposes this tab view, and allows you to display many view controllers inside a tab. And wait, let me just see if I can show you an example. For example, here you can recognize that this is a navigation view controller, but it's inside a tab view controller. And you know that it's the navigation controller inside a tab view controller because while your're navigating through here, and you can probably go multiple steps. You can switch the tabs to some where else, and when you come back the navigation stack still remains the same. Which means that your switching the whole navigation controller out. Probably there's another navigation controller somewhere you can do. We can see this is presenting of the controller. Let's look at these things. Because it goes over the tab view controller. So now when you present which was discussed in the first lecture of this module, with a segue. When you present and display a model, it goes over everything. So, even though it's still within a tab you control you can't just, go to a different tab when this is displayed like that. Now when you go back you're still at a navigation stack looks like you can go even farther down, which is pretty cool. So how do we use a tab view controller? Again, we're going to do this in a story board, which is a great way to visualize these kinds of things and usually it does a pretty good job. So we're going to keep our navigation controller since it's pretty common that you have navigating controller instead of tab controller. Again, we're going to use the embed feature inside editor menu to embed this in the tab bar controller. When you click on that, again, everything gets pushed to the right some more. Now you have a tab controller with a nav controller as its first tab. And everything else remains the same. So immediately you see this weird box down here, and that's, well that's the first tab, this is the tab bar. It's a bit thicker than a navigation bar. And it's even less flexible. So the navigation bar you can control, you can add custom items, you have a title. In the tab bar, you only have one tab bar item which is one icon in optional text or optional icon in text per tab. You can't have anything else, you can sort of control how they're laid out, like how they're spaced. But that's it. So, this one looks weird here because we don't have an image for it. There's also a few system options that are pretty useful and actually can handle lots of cases that you may have, like recents. We're going to say that this one is the favorite, so we'll give it like featured, have a nice star for it, so that would be this tab. And to add another tab, different from the navigation controller which only has one root controller, because that's how it works. A tab controller can obviously have more than one new controller at its root. So we're going to add another controller down here without a navigation bar. You can add another segue, so it's different. It's not called a root view controller anymore, so it's a relationship to its view controllers. And, basically, it's a new tab. Immediately when you do that, automatically, this guy gets its navigation item, I mean its tab item. And like a navigation item that the view controls itself customizes the look of this icon. And here you get sort of a preview of what that looks like in the tab bar controller. So we're going to say that this tab is, A different one or I'll say it's presets. And I'm going to give a nice background color to distinguish it, fiery red. All right, so we're going to leave it at two for now, and when you build and run go to our nice social thing. We now have a tab bar and it starts, it always defaults to the first view controller, and you can change that in code. You can customize it from the controller itself. Probably, maybe the bar, maybe not. All right. But you can now tap on the tab and automatically it changes the tab for you. And there's no animation here, that is intentional. There's not meant to be animation. It's as responsive as possible. And just like in the health app, if I push onto this first view controller, and I go to recents, it just switches away. So in the tab controller, all of these tabs are alive at all times. When you switch away, this guy stays alive. The whole navigation stack stays alive. This whole controller and everything on it stays alive so that so that basically they all have their own states. They're basically running in parallel and you can switch back and forth at anytime. So, that means in this paradigm, you don't want anything here on one tab controlling a different tab. They should function separately when you're using a tab controller because it can be very messy. And you'll have a terrible time trying to perform something on this tab through an action on this tab. All right, so that's the basic idea of tab controllers, the tab controllers stores an array of view controllers, which are all tabs, and they can be navigation view controllers, they can be any sort of custom view controller. And this displays them down at the bottom. And they need to have a tab bar item which customizes the item. And that's all there is to a tab controller. It's a lot simpler than a navigation controller. There's no concept of the stack and such. But there is one interesting one which is sort of the more tab. So if you have enough tabs, we're going to go ahead and copy and paste this guy a few times so we have one, two then we're going to go up to a few more. So if you have five, maybe six, we'll do one more. I'm just copying and pasting these guys. Now I've got six ViewControllers and I'm going to make them all tabs. So when there's too many tabs, iOS actually automatically sort of coalesces them for you into this more tab. We have six here. And it looks like it can display nicely from the storyboard's point of view. When you run, there's not going to be enough space for six tabs. In fact, there's only space for five. And so automatically you get this more button. When you press it, you get this free navigation button, you can even edit this, to organize the tabs. This is all free in the system. And look how cool that is, you can you can organize these tabs. It's kind of cool. But you can go to the tab, but with this extra tab on top. So basically, all these tabs are still standalone and all work. But you get this interesting navigation tab here. This thing becomes one tab that has a navigation controller with a table view where each row goes to the rest of your view controllers. And this is all free, so this is very convenient, and you can see this being used in, say, Facebook app, and you can customize this as well. So that's all there is really to tab controllers. In the beginning of this relationship segue on the prepare for segue also gets called on the tab controller and when it sort of embeds this view controller. So you can do some customizations there as well. Otherwise, you can see that in the tab controller. All these tabs and view controllers are siblings of each other. Whereas in the navigation controller they're on a stack. And they have sort of a hierarchical relationship. So by using tab bars, tab controllers, and navigation controllers effectively, your app can do a lot of things, it can be pretty complicated. It can have many features and if you organize them nicely, these two tools are enough to perform the navigation of I would say easily 95% of apps. These will be all you need. So, I hope you enjoyed this module and we'll see you soon.