Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从iphone应用程序编辑通讯簿记录_Iphone_Edit_Addressbook_Abpersonviewcontroller - Fatal编程技术网

无法从iphone应用程序编辑通讯簿记录

无法从iphone应用程序编辑通讯簿记录,iphone,edit,addressbook,abpersonviewcontroller,Iphone,Edit,Addressbook,Abpersonviewcontroller,我想在iphone应用程序中编辑通讯录中的记录。但我不能编辑任何记录。这是我的密码 // In my First View Controller - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DetailViewController *detailViewController=[[DetailViewController alloc] initW

我想在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;
}
//在我的第一个视图控制器中
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
DetailViewController*DetailViewController=[[DetailViewController alloc]initWithRecordObject:record];
[self.navigationController pushViewController:detailViewController动画:是];
[详细视图控制器发布];
}
//------------------------------------
#进口
#进口
#进口
#导入“User.h”
@界面详细信息ViewController:UIViewController{
ABRecordRef记录;
//其他一些IVAR
}
-(id)initWithRecordObject:(ABRecordRef)myrecord;
//------------------------------------
@实现细节视图控制器
-(id)initWithRecordObject:(ABRecordRef)myrecord
{
self=[super initWithNibName:@“DetailViewController”捆绑包:nil];
如果(自我){
record=myrecord;
}
回归自我;
}
#pragma标记-编辑记录方法
-(无效)btneditcontacts:(id)发送方{
//取地址簿
ABAddressBookRef addressBook=ABAddressBookCreate();
ABRecordID recID=ABRecordGetRecordID(记录);
ABRecordRef record1=ABAddressBookGetPersonWithRecordID(addressBook,recID);
ABPersonViewController*personViewController=[[ABPersonViewController alloc]init];
//集合委托
personViewController.personViewDelegate=self;
//允许编辑信息
personViewController.allowsEditing=是;
//显示所选人员的联系信息
personViewController.displayedPerson=record1;
personViewController.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“返回”样式:UIBarButtonItems样式普通目标:自我操作:@selector(returnFromPersonView)];
APP_DELGATE.isContactEdited=是;
[self.navigationController pushViewController:personViewController动画:是];
[personViewController释放];
}
-(无效)从PersonView返回{
NSLog(@“在%s中”,函数);
[self.navigationController PopViewControllerInitiated:是];
}
#pragma标记-ABPersonViewControllerDelegate方法
-(BOOL)personViewController:(ABPersonViewController*)personViewController应为person执行默认操作:(ABRecordRef)person属性:(ABPropertyID)属性标识符:(abMultiValue标识符)identifier ForValue{
//[自我解散Modalviewcontrolleranimated:是];
返回否;
}
当我按下personViewController时,我看不到有关记录的任何内容。这是一个截图


非常感谢您提供的任何帮助。谢谢

看看苹果的帮助。一个对你有用的页面就是这个页面。我建议您只需看看这些页面,它们是不言自明的。

将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
}

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

谢谢你的链接。我已经阅读了链接中的信息。但它和我以前实现的一样。但它不起作用。我不明白我做错了什么。你注意到我的代码有什么错误吗?谢谢