Implement backBarButtonItem to send message to delegate before

inside NavigationController. I want to reimplement the back button in the second level contentviewview controller to call an additional method before it returns to the first level content table controller. In this method, I want to send a message to a self-implemented delegate to inform the first-level content view controller of the changes made to the seconds-level content view controller. After that I want to set up my view controller normally.

In the didSelectRowAtIndexPath of my first level controller, I have implemented:

SecondController *secondController = [[SecondController alloc] initWithNibName:@"Second" bundle:nil];
[secondController setDelegate:self];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"test" style:UIBarButtonItemStyleDone target:secondController action:@selector(didPressBack:)];
[[self navigationItem] setBackBarButtonItem:button];
[(UINavigationController*) self.parentViewController pushViewController:secondController animated:YES];
[secondController release];


So the back button on the second level shows "test" -text, but didPressBack: in secondController is not called.

Or is there a different approach to re-implementing the Back button on a second-level controller?


source to share

All Articles