天天看點

使用iOS系統中的編輯聯系人界面,其中的思路值得借鑒(繼承的思想)

http://willonboy.tk/

//ContactInfoCell.h

ABPersonViewController  *personViewVC;

@property(nonatomic, assign) UINavigationController *globalNav;

- (void)handleEditBtnClicked:(id)sender

{

    if (!personViewVC)

    {

        personViewVC = [ABPersonViewController new];

    }

    personViewVC.personViewDelegate = self;

    personViewVC.allowsEditing = YES;

    personViewVC.editing = YES;

    ABAddressBookRef abRef = [ABAddressBookDataControllermakeABAddressBookRef];

    personViewVC.displayedPerson = ABAddressBookGetPersonWithRecordID(abRef, self.entity.recordId);

    UINavigationController *subNav = [[UINavigationController alloc] initWithRootViewController:personViewVC];

    subNav.navigationBarHidden = NO;

    UINavigationBar *subNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, 320, 44)];

    subNavBar.barStyle = UIBarStyleDefault;

    UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"編輯聯系人"];

    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonSystemItemCancel target:self action:@selector(cancelEdit:)];

    UIBarButtonItem *okItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonSystemItemCancel target:self action:@selector(okEdit:)];

    navItem.leftBarButtonItem = backItem;

    navItem.rightBarButtonItem = okItem;

    subNavBar.items = [NSArray arrayWithObjects:navItem, nil];

    [subNav.view addSubview:subNavBar];

    [self.globalNav.topViewController presentModalViewController:subNav animated:YES];

    [subNavBar release];

    [navItem release];

    [backItem release];

    [okItem release];

    [subNav release];

    CFRelease(abRef);

}

- (void)cancelEdit:(id)sender

    [self.globalNav.topViewController dismissModalViewControllerAnimated:YES];

- (void)okEdit:(id)sender

    [[personViewVC editButtonItem].target performSelector:[personViewVC editButtonItem].action];

    NSLog(@"okedit");

    [self cancelEdit:nil];

- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property

identifier:(ABMultiValueIdentifier)identifier;

    return NO;

使用iOS系統中的編輯聯系人界面,其中的思路值得借鑒(繼承的思想)

<a href="http://github.com/willonboy">http://github.com/willonboy</a>

繼續閱讀