0

我想在我的 iphone 应用程序中编辑通讯录中的记录。但我无法编辑任何记录。这是我的代码

 // In my First View Controller

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   DetailViewController *detailViewController=[[DetailViewController alloc] initWithRecordObject:record];

 [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

//------------------------------------

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import "User.h"

@interface DetailViewController : UIViewController <UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate,ABPersonViewControllerDelegate> {

    ABRecordRef record;
    // Some other ivars
}
- (id)initWithRecordObject:(ABRecordRef)myrecord;

//------------------------------------

@implementation DetailViewController

- (id)initWithRecordObject:(ABRecordRef)myrecord
{
    self = [super initWithNibName:@"DetailViewController" bundle:nil];
    if (self) {
        record = myrecord;
    }
    return self;
}

#pragma mark - Edit Record Method

-(void)btnEditContactTapped:(id)sender {

    // Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreate();

    ABRecordID recID = ABRecordGetRecordID(record);

    ABRecordRef record1 = ABAddressBookGetPersonWithRecordID(addressBook,recID);

    ABPersonViewController *personViewController = [[ABPersonViewController alloc]init];

    // set delegate
    personViewController.personViewDelegate = self;

    // Allow editing info
    personViewController.allowsEditing = YES;

    // Display contact info of selected person
    personViewController.displayedPerson = record1;

    personViewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(returnFromPersonView)] ;

    APP_DELGATE.isContactEdited = YES;

    [self.navigationController pushViewController:personViewController animated:YES];

    [personViewController release];
}

-(void)returnFromPersonView {
    NSLog(@"In %s",__PRETTY_FUNCTION__);
    [self.navigationController popViewControllerAnimated:YES];

}

#pragma mark - ABPersonViewControllerDelegate Method

- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue {

    //[self dismissModalViewControllerAnimated:YES];
    return NO;
}

当我按下 personViewController 时,我看不到任何有关记录的信息。这是一个截图

在此处输入图像描述

非常感谢任何形式的帮助。谢谢

4

3 回答 3

0

您没有将“正确的联系人 ID”作为ABRecordRef;)

于 2014-03-15T12:59:00.330 回答
0

查看 Apple 的地址簿编程指南。对您有用的页面是直接交互:以编程方式访问数据库页面。我建议你看看那些页面,它们是不言自明的。

于 2012-04-23T10:48:55.680 回答
0

将返回更改为 YES 可能有助于最后一种方法

- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue {

//[self dismissModalViewControllerAnimated:YES];
return NO; //try changing it to YES
}
于 2012-04-23T11:27:48.793 回答