如何在iPhone应用程序中打开编辑联系人窗口?

时间:2011-12-20 12:45:35

标签: iphone objective-c abaddressbook

我在Addcontact点击中添加了我的iPhone应用程序的联系信息。我只想在同一个Addcontact点击上打开编辑联系人窗口,这样用户就可以编辑或删除刚刚添加的联系人。我做了类似下面的事情..

- (IBAction)AddContact
 {   
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef Showroom = ABPersonCreate();

//adding contact name as showroom name

ABRecordSetValue(Showroom, kABPersonFirstNameProperty, ShowroomName.text , nil);
   ABAddressBookAddRecord(addressBook, Showroom, nil);
ABAddressBookSave(addressBook, nil);
// Fetch the address book 
//ABAddressBookRef addressBook = ABAddressBookCreate();
// Search for the person named "Appleseed" in the address book

    //ABRecordRef Showroom = (ABRecordRef)[Showroom objectAtIndex:0];
    ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
    picker.personViewDelegate = self;
    picker.displayedPerson = Showroom;
    // Allow users to edit the person’s information
    picker.allowsEditing = YES;
[self.navigationController pushViewController:picker animated:YES];
}

这是我的地图应用程序。在发布时,我得到了联系人的陈列室结果。这个我可以添加到编辑联系人窗口打开的iPHone联系人。但是当我打开其他控制器将用户选择的字符串地址传递给Map控制器来搜索陈列室位置时。上面的代码不起作用。我的意思是它只添加联系人,但我没有得到编辑联系窗口。

修改 可能这个问题是关于导航控制器吧所以检查下面的代码也是

- (void)viewWillAppear:(BOOL)animated 
   {
  [self.navigationController setNavigationBarHidden:YES animated:animated]; 
   } 
   - (void)viewDidLoad {

[self.navigationController setNavigationBarHidden:NO ];
self.navigationController.navigationBar.tintColor = [UIColor  colorWithRed:25.0/255.0f green:25.0/255.0f blue:25.0/255.0f alpha:1.0f];
   }
- (void)viewWillDisappear:(BOOL)animated
{ 
[self.navigationController setNavigationBarHidden:NO animated:animated];
 }

1 个答案:

答案 0 :(得分:0)

我希望这段代码适合你,我实现了代码,在我的应用程序中工作正常,谢谢

contecviewcontroller.h
@interface DetailsViewController : UIViewController
DocumentNavController *coffeeObj;
editViewController *evController;
int currentindex;
}

@property (nonatomic, retain) DocumentNavController *coffeeObj;
@property (readwrite, assign) int currentindex;    
@end

contecviewcontroller.m

- (void)viewDidLoad {
  [super viewDidLoad];
//self.navigationController.toolbar.tintColor = [UIColor darkGrayColor];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
                                           initWithBarButtonSystemItem:UIBarButtonSystemItemEdit 
                                           target:self action:@selector(goToEdit)]autorelease];
}


-(void)goToEdit{

if(evController == nil)
    evController = [[editViewController alloc]initWithNibName:@"editViewController" bundle:nil];
evernoteAppDelegate *appdelegete = (evernoteAppDelegate *)[[UIApplication sharedApplication]delegate];
coffeeObj = [appdelegete.noteArray objectAtIndex:currentindex];

evController.Editcurrentindex = currentindex;
evController.docedObj = coffeeObj;
[self.navigationController pushViewController:evController animated:YES];
}