programming4us
programming4us
MOBILE

iphone SDK : Using the ABPersonViewController Class, Using the ABNewPersonViewController Class

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

1. Using the ABPersonViewController Class

The ABPersonViewController class allows you to present the details of a specific record to the user. As with its other sisters, you need to create it and initialize it. Next, you set its delegate (one method to implement). After that, you configure some of its options. The allowsEditing property is set to YES if you want the user to edit the record. NO is the default. The displayedPerson must be set to the person record you want to show. The displayedProperties is an array of all properties you want to show. If you allow editing, then the other properties will show as well while editing.

If you want to highlight a given property, use the setHighlightedItemForProperty:with-Identifier: method which is declared as follows:

- (void)setHighlightedItemForProperty:(ABPropertyID)property
          withIdentifier:(ABMultiValueIdentifier)identifier;

The property parameter specifies the property identifier you want to highlight. If the property is single-value, the second parameter is ignored. If, on the other hand, the property is multi-value (e.g., phone), the identifier specifies which value to highlight. You can highlight as many values as you want.

Listing 1 shows how one can setup and invoke a person view controller. In this example, we retrieve the first person record and show it. The displayed properties are the phone and email properties. The method also highlights the phone value with identifier 0.

Example 1. Showing a person record using the ABPersonViewController class.
-(void)buttonPushed{
  ABAddressBookRef addressBook = ABAddressBookCreate();
  NSArray    *allPeople =
    (NSArray*) ABAddressBookCopyArrayOfAllPeople(addressBook);
  if(allPeople.count){
    ABRecordRef person = (ABRecordRef)[allPeople objectAtIndex:0];
    ABPersonViewController *personViewController =
       [[[ABPersonViewController alloc] init] autorelease];
    personViewController.personViewDelegate = self;
    personViewController.displayedPerson = person;
    personViewController.displayedProperties =
    [NSArray arrayWithObjects:
     [NSNumber numberWithInt:kABPersonEmailProperty],

[NSNumber numberWithInt:kABPersonPhoneProperty], nil];
    [personViewController
        setHighlightedItemForProperty:kABPersonPhoneProperty
        withIdentifier:0];
    [self presentModalViewController:personViewController animated:YES];
  }
  [allPeople release];
  CFRelease(addressBook);
}

Listing 2 shows the delegate method of the person view controller. If the property selected by the user is an email property, we log it, disallow default action, and dismiss the controller. Otherwise, we dismiss the controller and allow default action to occur.

Example 2. The delegate method of a person view controller.
- (BOOL)
     personViewController:(ABPersonViewController *)personViewController
     shouldPerformDefaultActionForPerson:(ABRecordRef)person
     property:(ABPropertyID)property
     identifier:(ABMultiValueIdentifier)identifierForValue{
  if(property == kABPersonEmailProperty){
    ABMultiValueRef emailProperty = ABRecordCopyValue(person, property);
    NSInteger emailndex =
     ABMultiValueGetIndexForIdentifier(emailProperty, identifierForValue);
    NSString *email =
      (NSString *)ABMultiValueCopyValueAtIndex(emailProperty, emailndex);
    NSLog(@"The email  selected is %@:", email);
    CFRelease(emailProperty);
    [email release];
    [self dismissModalViewControllerAnimated:YES];
    return NO;
  }
  else{
    [self dismissModalViewControllerAnimated:YES];
    return YES;
  }
}

					  

Figure 1 shows a view from the person view controller.

2. Using the ABNewPersonViewController Class

If you want the user to create a new person record, you can use the ABNewPersonViewController controller. You create and initialize the controller and set the delegate. The controller is then pushed on the stack. The following shows a typical invocation:

Figure 1. A view from a person view controller.

ABNewPersonViewController *newPersonViewController =
 [[[ABNewPersonViewController alloc] init] autorelease];
 newPersonViewController.newPersonViewDelegate = self;
 [self.navigationController
   pushViewController:newPersonViewController animated:YES];

The only delegate method is newPersonViewController:didCompleteWithNewPerson:. You should dismiss the controller and inspect the new person record. Note that the person will be added to the address book by the time this method is called. If the user cancelled, the person parameter is NULL.

- (void)
newPersonViewController:(ABNewPersonViewController *)newPersonView
    didCompleteWithNewPerson:(ABRecordRef)person{
  [self.navigationController popViewControllerAnimated:YES];
}

Figure 2 shows the view of ABNewPersonViewController controller.

Figure 2. Adding a new contact using the ABNewPersonViewController class.

Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us