MapVC Interface
Start course
3h 18m

In this course, we're going to build a Foursquare Clone using Parse. Parse provides you with a great tool to work in cloud servers and you will learn the advantages and disadvantages that come with it.

Intended Audience

This course is designed for anyone who wants to:

  • Learn about iOS development and coding
  • Move into a career as an iOS developer
  • Master Swift skills


To get the most out of this course, you should have some basic knowledge of iOS.


Hi, within this lecture, we're going to add our new map view controllers so that after user hits Next, they're yet to choose the coordinate from a map.  So, let me bring in one view controller from here. Later on, I'm going to add one map kit in this view controller and what I want to have is a segue from add place view controller to this view controller and this is going to be a show segue and will display some kind of bar button over here. And I'm going to name this toMapVC.  So, in my previous segue, I don't have identifier again, so I'm going to name this toAddPlaceVC as well.  So, now I'm done with segues. Let's bring in map kits.  So, let's say, Map Kit View and within this view controller, I am only going to need one map view, so I'm going to come over here and say 0, 0, 0, 0 to all four constraints and it will stretch all the way to the edges so that I have a field up map view in my new view controller. So, that's what we want. In here, I can have a save button or upload button in the bar button or I can place it anywhere inside of the view controller as well. In my case, I'm going to go ahead with the bar button item and I'm going to add it on my bar button.  So, let me create a new Cocoa Touch Class and let's call this MapsVC or MapVC and place it under our project folder. Later on, I'm going to go ahead and delete everything in here and go to main storyboard and find our latest view controller and go to the identity inspector to choose MapVC.  So, if I come over to my MapVC, now I can bring in this map Kit, map view to my MapVC and I'm going to call this map view.  So, this is going to be my map view.  So, let me close this down, and as you can see, we get some errors and it's because I don't have map Kit imported in my project.  So, let me import the MapKit, and here we go. Now the errors went away.  So, we are ready to do what we want to do inside of this MapVC. However, in this condition we cannot even test to see if our map works or not because we don't have the segues yet.  So, in the AddPlacesVC, I don't have segue to go to the next view controller and in here as well, I don't have any segue right now.  So, under addButtonClicked, I'm going to perform a segue and the identifier will be toAddPlaceVC and the sender will be nil. And in the AddPlaceViewController, I'm going to perform a segue one more time then user clicks on 'Next' and it will take us to the MapVC. And under MapVC, I'm going to add the save button that I was talking about.  So, let me delete this, and under viewDidLoad, I'm going to go for navigationController.navigationBar.topItem and a right bar button item and this will be a UIBarButton, this one UIBarButton, and I'm going to go for this title one more time because I just want to save this.  So, style will be plain, target will be self action, let me create a selector and then we're going to add a new objective C function here.  So, this is going to be at objective C function, so saveButtonClicked.  So, that's it, I'm going to assign this saveButtonClicked to be my selector function. And in the saveButtonClicked, I'm going to do whatever I want to do to upload all of this information to my Perse Server. And we're not going to do that now, we're going to do that later on.  So, let me test, let me see if we can see all the view controllers without any error.  So, if I click on here, it will take us to the AddPlaceViewController, and that's fine. If I click on 'Next', it will take me to my maps, and one error that I have seen in here that I don't have my Save button.  So, if I go back I will see the Save button in my AddPlaceViewController. Even though I have written this code inside my map view controller, it displays that Save button in the AddPlaceViewController. This is some sort of mix up. I don't want that.  So, why does it happen?  Since MapVC doesn't have its own navigation controller, it kind of doesn't understand where should it put the Save button.  So, if we come over here to Mainstoryboard, as you can see, we don't have any navigation controller just in front of this map view controller. We only have it in front of our places view controller.  So, what I'm going to do, I'm going to add a new navigation controller in front of my map view controller so that I don't have that kind of problem.  So, this will have its own navigation controller  and when I write that code it will understand where to put it.  So, it raises new questions. It raises new problems as well. Because right now, I don't have any Back button coming up because I'm doing this show segue to navigation controller and it will create a new navigation bar in here. We're going to take care of that problem later on.  So, let's test this and see if we can actually manage to show the Save button to the user. Let me go over here and click on this Add button, and let me click on that Next button. Here you go. Now, we see the Save, but we see it as a pop over segue, so I don't want that. I just want this as a full screen mode.  So, I'm going to do this Present Modally, and if I do this full screen then I believe this will take care of our problems.  So, let's open this one more time and see if we can get a full good looking UI view controller. Here we go. Now, we see the Save button but actually we lost the Back button because we have a navigation controller along the way.  So, it's fairly to overcome that problem. We can add a new navigation controller bar button item over here.  So, let me just come over here and say navigationController.navigationBar .topItem.LeftBarButtonItem. This is going to be a UIBarButtonItem and will ask us for a title and a style. Let me just open this one more time, item. In fact, we can actually test to see if there is a system button for going back, and let's see action, add, bookmarks, cancel. Maybe we can do something like cancel as well, but I believe there is no Back button option over here. And you can try cancel or you can try others, but I'm going to go for title again because we don't have Back button.  So, let me go to title and I'm going to do something like this like back with this small sign over here. In style, I'm going to go for plain one more time. You can choose the other ones and see how it looks like. And maybe having a Back button is not a very good idea in this case because maybe we want to go back to places view controller once the user cancels this. But in any way I will show you how to have a back button in this case because it will actually improve your skills as well.  So, let me say backButtonClicked, and let me give the selector to here as a selector function, and under backButtonClicked, can I do navigationController.popViewController with animation. No, I cannot do that. This won't work. Because previously we had only one navigation controller and popping one item back works. Now, I have a new navigation controller along the way in the middle of our view controllers, so there is no view controller to pop back. So, this won't work.  So, I'm going to comment this out. Rather I'm going to use something called self.dismiss and this will dismiss the current view controller and go back where we were previously.  So, let me run this and show you how this works. Let's go to our simulator and hit on Plus button. It will take us here, and if you say Next, this will display the Save button on the right hand side and Back button on the left hand side. If I hit 'Back' now I'm back in Add places. If I hit 'Back' now I'm back in places view controller, so that actually works. Now, there is only one view controller left to add here, and we're going to do that in the next lecture.


About the Author
Learning Paths

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics