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 をプッシュすると、レコードに関して何も表示されません。ここにスクリーンショットがあります

ここに画像の説明を入力

どんな種類の助けも大歓迎です.Thanks

4

3 に答える 3

0

Apple のAddress Book Programming Guideを見てください。あなたにとって役立つページは、直接対話: プログラムによるデータベースへのアクセスページです。これらのページをざっと見て回ることをお勧めします。

于 2012-04-23T10:48:55.680 に答える
0

return を 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 に答える