views:

363

answers:

1

Hi all I am using ABPersonViewController and adding a label on the "Info" view. The thing is: when I click the "Edit" button, since the : personController.allowsEditing = YES; my view goes to the "edit view" and my Label is still there (not as I planed ) I am trying to figure out if I can be "notify" when the user pressed the "Edit" button , so I can remove my label from the current view before it goes to the "Edity View"

The only option I am thinking about is to disable editing in ABPersonViewController and to create an "Edit" button of my own, then I will have to try and implement the same behavior of the Addressbook "Edit" button ...

Is there an option for a callback , when the "Edit" button is pressed ? and still keep the same behavior of the ABPersonViewController?

or maybe there is a way to know on which view I am in (tag or somthing ... ?) in the ABPersonViewController so I can remove the label when I am not on the "Info" view

Thanks

Itay

A: 

Just figured out a slightly hacky looking way to get notified when edit is pressed.

create a subclass of ABPersonViewController and attach your own custom action to the edit button: In the initialization for your view controller:

-(void)viewDidAppear:(BOOL)animated{

[self.navigationItem.rightBarButtonItem setTarget:self];
[self.navigationItem.rightBarButtonItem setAction:@selector(editPressed)];

}

I couldn't find a better reference to the edit button than: self.navigationItem.rightBarButtonItem

then create your editPressed action:

-(void)editPressed{

[super setEditing:!super.editing];

if(self.editing){

   NSLog(@"Editing");

   //Insert code to put your custom view in edit mode

}else{

   NSLog(@"Not editing");

  //Insert code to take your custom view out of edit mode

}

}

It's important to call [super setEditing:!super.editing] first as this makes the UIPersonViewController go in and out of edit mode as appropriate (Defining your custom action overwrites the default action). It also properly updates the the 'editing' property of your view controller so that 'self.editing' gives the correct value.

Beverley