Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


patrick tagliaferro
patrick tagliaferro
5,399 Points

UILabel tap to call

I am pulling a number from parse the following way and displaying it in a label. How can I add a tap gesture to make the call?


    [super viewDidAppear:animated];

    //FInd the Agent and show it
    self.agentRelation = [[PFUser currentUser] objectForKey:@"agentRelation"];
    PFQuery *query = [self.agentRelation query];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // success

            self.agent = objects;
            // Do something with the found objects
            for (PFObject *object in objects) {
                NSLog(@"name: %@", [object objectForKey:@"name"]);
                NSLog(@"email: %@", [object objectForKey:@"email"]);

                NSString *displayEmail = [object objectForKey:@"email"];
                NSString *displayName = [object objectForKey:@"name"];
                NSString *displayPhone = [object objectForKey:@"phone"];

                PFFile *thumbnail = [object objectForKey:@"profilePic"];
                NSURL *imageFileURL = [[NSURL alloc] initWithString:thumbnail.url];
                NSData *imageData = [NSData dataWithContentsOfURL:imageFileURL];

                self.agentEmail.text = displayEmail;
                self.agentName.text = displayName;
                self.agentPhone.text = displayPhone;
                self.agentImage.image = [UIImage imageWithData:imageData];


        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);


1 Answer

arbi Derhartunian
arbi Derhartunian
2,864 Points

You could add the following method in your viewController and add the call on the tap gesture

  • (void)handleTap:(UITapGestureRecognizer *)sender


if (sender.state == UIGestureRecognizerStateEnded)


    // handling code



you can read more about gestures on https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITapGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UITapGestureRecognizer

patrick tagliaferro
patrick tagliaferro
5,399 Points

Thanks. From what I read it might be easier to just make a button and have the title and the action pull the number from parse.