iOS7 - ABPersonViewController, editing mode

孤人 提交于 2019-12-05 13:32:24

问题


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];
    }   
    ...
    ...
}

回答1:


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];


来源:https://stackoverflow.com/questions/19099071/ios7-abpersonviewcontroller-editing-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!