Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:13:00+00:00 2026-05-30T10:13:00+00:00

I am VERY new with iOS development. So, please make your response as exact

  • 0

I am VERY new with iOS development. So, please make your response as exact and basic as possible.

I have a form with two (at the moment – there could be more) fields that will have a button next to each that allows the user to select a contact from the iPad address book and fill the relevant field with the first and last name from the address book.

Basic Form Mockup

The example code I have got me to the point that I can fill in the Contact Name. However, I would like to be able to click on the ‘Browse Contacts’ button next to Referred By, and have it use the same functions to fill in the referred by name. I see that the getContactName function has the sender parameter. So, I could easily tell which of the two buttons (or others later) were clicked.

But, when I pick from the address book, how do I know which button was clicked in the peoplePickerNavigationController or fillContactName functions?

- (IBAction)getContactName:(id)sender {

    ABPeoplePickerNavigationController *picker =
    [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;

    [self presentModalViewController:picker animated:YES];
}


- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
        [self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    [self fillContactName:person];

    [self dismissModalViewControllerAnimated:YES];

    return NO;
}

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier
{
    return NO;
}


- (void)fillContactName:(ABRecordRef)person
{
    NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person,
                                                                    kABPersonFirstNameProperty);

    NSString *test = [firstName stringByAppendingString:@" "];

    NSString* lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person,
                                                                         kABPersonLastNameProperty);

    NSString *fullName = [test stringByAppendingString:lastName];

    self.contactName.text = fullName;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:13:01+00:00Added an answer on May 30, 2026 at 10:13 am

    Here’s one way you could do it.

    First, assign your “Browse Contacts” button unique int values for their tag property when they are created (or in the storyboard, if you are using storyboards) so that you can tell them apart in your getContactName: method. I would suggest setting tag=0 for the first button and tag=1 for the second button.

    Then add a new property to your ViewController class that will store a pointer to the target text field after the button is clicked. (Be sure to @synthesize in your .m file)

    @property (nonatomic, strong) UITextField *targetTextField;
    

    In getContactName:, inspect the sender object and use its tag value to set the pointer appropriately. (Note that the sender will be the UIButton object that the user clicked).

    - (IBAction)getContactName:(id)sender {
    
        ...
    
        switch(sender.tag) {
            case 0:
                self.targetTextField = self.contactName;
                break;
            case 1:
                self.targetTextField = self.referredBy;
                break;
            default:
                self.targetTextField = nil;
        }           
    
        [self presentModalViewController:picker animated:YES];
    }
    

    Then in fillContactName:, set the text value to the text field at the targetTextField which you have previously set.

    - (void)fillContactName:(ABRecordRef)person
    {
        NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
        NSString* lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);
    
        self.targetTextField.text = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
    }
    

    Note that I have used the NSString class method stringWithFormat: to make your fillContactName code more concise. This is a commonly used method in a case like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: I am very new to iOS development. Please excuse the possible stupidity of
I'm very new with iOS Development and I have just created one of my
i am very new to ios development, rather i have just started work on
I still very new using Subversion. Is it possible to have a working copy
I am a new iOS developer. I got a very basic doubt. I read
I'm very new to IOS programming and i have doubt with NSThread. My problem
I am very new to IOS programming. I have a task to find if
Very new to programming for iOS and Cocoa so please take it easy on
I am very new to iOS Programming and have been learning for only a
I'm still very new to the iOS SDK. Is it possible to hook into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.