- Creating a custom control for adding new items
- Adding a custom initializer
- Passing data using delegates and closures
- Creating a generic data provider
- Implementing a generic data source
- Saving records
- Adding segues between views
- Using lean controllers
- Using extensions
Skill Level Intermediate
- [Instructor] And welcome back. Before we go ahead and start implementing our custom control, we should have an idea of why we are doing that. So let's go ahead and first let's run the application and see our interface. So you'll see that we are displaying Shopping Lists. And the custom control or the input control we are talking about is this top part where I can enter in name of the Shopping List. The code to create that text box is contained inside the viewForHeaderInSection delegate method of the UITableViewDelegate.
So basically this is all the code that is required to create the text box. And this works really fine. The problem arises when I click on or press or select a certain type of a Shopping List and it goes to a new screen. Now maybe on this screen I also want the control to input a grocery item, meaning I want to enter a cookie or chips, or milk or bread, using the same kind of input control or a text box control.
Of course at this point you might be wondering hey, that's not really hard because I'm gonna just copy out this code and paste it in my new view controller. And as I explained earlier, copy pasting is a root of all evil in software development. So instead of copy pasting it multiple times, what we can do is we can create a separate component, separate file which we can add, which will be the AddNewItemView.
AddNewItemView. And the whole purpose of AddNewItemView will be to display the control that we have seen. So the whole point of the AddNewItemView will be to display that text box and to communicate with whoever it tries to communicate with, which is a view controller. So we can move the whole functionality, whole look and feel, off the text box or the control that is displayed on the top into a separate component, separate control AddNewItemView.
Now let's say in the future you want a different font over here, different color, different kind of effects. Guess what? You only have one file, AddNewItemView. You are going to go over to there and change the look and feel, the functionality, the behaviors, and it will be reflected everywhere in your application. And in the next lecture we're going to dive in and see how we can do that. Thank you very much.