使用iOS系统中的编辑联系人界面
On 2012/12/04, in Objective-C, iOS控件, by willonboy
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;
}