How can I override the Finish button in ABNewPersonViewController

I have a class that subclasses ABNewPersonViewController . As I understand it, when the "Finish" button on the navigation bar is clicked, the delegate method

 - (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person 

called out. But before entering the delegate method, the changes will be saved in the address book.

I need it as soon as the save button is pressed. I need to load a UIView with two buttons asking the user,

  • does he want change and
  • should he interrupt the changes made,

But this must be done before the changes are reflected in the address book. And only when you click the first button in the UIView , the changes must be saved in the address book.

When the second button is clicked, the view should disappear, and I should return to the view controller class, from where the UIView loaded.

My question is how to upload the image to the "Save" button before the changes are reflected in the address book

I created a custom save button

 UIBarButtonItem *okBtn = self.navigationItem.rightBarButtonItem; UIBarButtonItem *saveBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:okBtn.target action:okBtn.action]; self.navigationItem.rightBarButtonItem =saveBtn; [saveBtn release]; 

In the save button action, the control moves to the delegate method

  - (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person` . 

I want the control to go to my custom method, where I can load my UIView before the changes are saved in the address book.

Edit: When I load ABNewPersonViewController

  ABPersonViewController *displayVcardViewController = (ABPersonViewController*)[self.navigationController visibleViewController]; ABRecordRef person = displayVcardViewController.displayedPerson; EditAddressNewPersonDetailViewController *newVCardViewController = [[EditAddressNewPersonDetailViewController alloc] init]; newVCardViewController.displayedPerson = person; newVCardViewController.newPersonViewDelegate = self; newVCardViewController.isEditingMode = YES; [self.navigationController setToolbarHidden:YES]; [self.navigationController pushViewController:newVCardViewController animated:YES]; [newVCardViewController release]; 

Is this strong link already or not. Where should I include a strong link.

On

 - (void)actionSave:(UIBarButtonItem *)sender { if([[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]) { [self.myView setFrame:CGRectMake(0, 0, 320, 480)]; [[UIApplication sharedApplication].keyWindow addSubview:self.myView]; UIActionSheet * action = [[UIActionSheet alloc]initWithTitle:@"" delegate:self cancelButtonTitle:@"Do" destructiveButtonTitle:@"Cancel" otherButtonTitles: nil]; action.tag = 101; [action showInView:self.view]; [action release]; } } 

I am loading a UIView with a UIAlertView above it.

+4
source share
1 answer

Update . Starting with iOS 7.0, ABNewPersonViewController no longer subclassed, and this will not work.

First save the reference to the default value of rightBarButtonItem before overriding it. If you subclass ABNewPersonViewController , your viewDidLoad will look like this:

 - (void)viewDidLoad { [super viewDidLoad]; // Store the old button item into a custom property // @property (nonatomic, retain) UIBarButtonItem *defaultRightBarButtonItem; self.defaultRightBarButtonItem = self.navigationItem.rightBarButtonItem; UIBarButtonItem *saveBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(actionSave:)]; self.navigationItem.rightBarButtonItem = saveBtn; [saveBtn release]; } 

And you invoke the default action for the default target in your custom action method:

 - (void)actionSave:(UIBarButtonItem *)sender { // Do what you want to do before the data is saved // .... // .... // Trigger the default action [self.defaultRightBarButtonItem.target performSelector:self.defaultRightBarButtonItem.action withObject:self.defaultRightBarButtonItem.target]; } 
+4
source

Source: https://habr.com/ru/post/1398795/


All Articles