2012-04-23 17 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

は、AppleのAdress Book Programming Guideを見てみましょうです。あなたにとって役に立つページはDirect Interaction: Programmatically Accessing the Databaseページです。これらのページを見てみることをお勧めします。 YESへの復帰を変更

+0

リンクいただきありがとうございます。私はリンクから情報を読んだ。しかし、それは私が実装に使用したものと同じです。しかし、それは動作しません。私が間違っていることを私は得ていない。私のコードで何か間違っていることに気付きましたか?ありがとう – iOSAppDev

0

は最後の方法で

- (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

0

を助けるかもしれないあなたはABRecordRefとして「正しい連絡先ID」を渡していません。)

関連する問題