iOS7 - ABPersonViewController, editing mode
Asked Answered
C

1

13

Apple features a nice comprehensive and small example, "QuickContacts" (developer.apple.com/library/IOs/samplecode/QuickContacts/Introduction/Intro.html), outlining the basic usage of the Address Book UI Framework. - The downloadable sourcecode works as described (once you add a person named "Appleseed" to your addressbook or change the person-name in line 246 (of QuickContactsViewController.m) to something that already exists in your addressbook).

Question: How can we modify the function -(void)showPersonViewController function in such a way that the ABPersonViewController "picker" is already in editing-mode (with a visible "Done" editingButton), when it opens (after being pushed onto the navigationController's stack).

In iOS versions prior to "7", it was a straight-foward matter of just inserting e.g. picker.editing = YES; before pushing the picker onto the nav-stack, in order to see it in editing-mode, once it opens (see code below).

In iOS7, this does not work anymore.

Is this a bug in iOS7, if so, is there a simple work-around (rather then e.g. reverse-engineering the ABPersonViewController class)? - Or does it need to be coded differently, these days?

Looking forward to your comments.

-(void)showPersonViewController
{
    // Search for the person named "Appleseed" in the address book
    NSArray *people = (NSArray *)CFBridgingRelease(ABAddressBookCopyPeopleWithName(self.addressBook, CFSTR("Appleseed")));
    // Display "Appleseed" information if found in the address book 
    if ((people != nil) && [people count])
    {
        ABRecordRef person = (__bridge ABRecordRef)[people objectAtIndex:0];
        ABPersonViewController *picker = [[ABPersonViewController alloc] init];
        picker.personViewDelegate = self;
        picker.displayedPerson = person;
       // Allow users to edit the person’s information
       picker.allowsEditing = YES;

       picker.editing = YES;   // in iOS6 this works, in iOS7 it does not

       [self.navigationController pushViewController:picker animated:YES];
    }   
    ...
    ...
}
Cloutman answered 30/9, 2013 at 16:20 Comment(3)
This is a bug in iOS 7. The more folks who report it the higher priority fix will be assigned. bugreport.apple.comFelicafelicdad
@ Tommie C. - You are right, Apple confirmed it's a bug. - Thank's for your comment.Cloutman
This still hasn't been fixed it seems??Osmund
D
10

You can use ABNewPersonViewController instead of ABPersonViewController,bellow is the code :

ABNewPersonViewController *picker = [[[ABNewPersonViewController alloc] init] autorelease];
picker.newPersonViewDelegate = self;
picker.displayedPerson = person;
picker.navigationItem.title=@"edit contact";

[self.navigationController pushViewController:picker animated:YES];
Dc answered 23/5, 2014 at 6:48 Comment(1)
in protocol method -(void)newPersonViewController:didCompleteWithNewPerson: ABRecordRef person will be either NULL (if user cancel editing) or original value (initialized at picker.displayedPerson = person;)Fluorescent

© 2022 - 2024 — McMap. All rights reserved.