Choosing Image

Start course
Overview
Difficulty
Intermediate
Duration
3h 18m
Students
11
Description

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

Prerequisites

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

Transcript

Hi, within this lecture, we're going to add our chooseImage() function to our AddPlaceVC so that user can tap on this picture in order to go to the photo gallery and choose an image to display in that imageView, and you know how to do that already, right? Because we have been doing it so far, so I suggest you pause the video and try to do it on your own. So, we're going to work with this placIemageView. And first of all we have to make this user interaction enabled so that when we add a new gesture recognizer to it, it gets recognized and we get to call whatever function we want, okay? So, what I'm going to do, I'm going to say placeImageView, so this one placeImageView.isUserInteractionEnabled is going to be true. After doing that of course, I can call, I can create my gesture recognizer. So, this is going to be a gestureRecognizer and this is going to be a UITapGestureRecognizer. So, target will be self and of course, we're going to have to create a new selector function. So, let me do that over here. This is going to be an objectReceive() function, chooseImage and we can come over here and say chooseImage. And after that we have to add this to our placeImageView and say addGestureRecognizer and readGestureRecognizer. So, the gesture will be tapped and when we recognize this gesture, we're going to create a UIPicker, imagePicker actually not picker, UIImagePickerController over here. So, the speaker will have the delegate of our self, our current ViewController, and of course in order to do that, we have to come up over here and say this is indeed a UIImagePickerControllerDelegate, and on top of it it's actually a UINavigationControllerDelegate. So, I'm doing this fast because we have done it so many times and over here we have to specify the source type as well as photoLibrary and then later on you can just call self.present and present the picker, animated. Why not? Completion will be nil. So, after that we have to specify what will happen once the user chooses the image. In order to do that, we're going to have to work with notDidFinishLaunching but didFinishPickingMedia. So, if you write didFinishPickingMedia, it will just pop up. So, this is didFinishPickingMediaWithInfo. So, what are we going to do? We're going to say placeImageView.image. We're going to pick that image from this info and this gives us a dictionary in which we will give original image as a key and this will give us a value and we're going to cast that value as a UIImage and then we're going to dismiss and say completion is nil. So, of course if you want any description to give, you can come over to info.place and give it yourself because you know how to already do that. So, let's run this on our simulator and let's see if we can get the image. So, let's click on the 'Add' button, let's click our 'imageView' over here, and it will take us to our photoLibrary and choose one of the images, and here we go. Now we see the image. If I click over one more time, now I can get another image as well. Now I can write the name type and atmosphere and I can choose an image so that I can hit next to choose the coordinates, right? Now, all I have to do is just find a way to transfer all of this information to the map view so that I can upload all of this information along with the coordinates with latitude and longitude to the Parse server. That's what we're going to do in the next lecture.

 

About the Author
Students
951
Courses
55
Learning Paths
3

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