2012-04-23 56 views
0

我想在我的iphone應用程序中編輯地址簿中的記錄。但我無法編輯任何記錄。這裏是我的代碼無法編輯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,我看不到任何關於記錄。下面是截圖

enter image description here

任何形式的幫助是非常appreciated.Thanks

回答

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 
} 
+0

仍然沒有工作 – iOSAppDev 2012-04-24 04:23:21

0

你是不是經過「正確接觸ID」爲ABRecordRef;)