Tengo un UITableViewController que inicia un UIViewController y me gustaría atrapar cada vez que se presiona el botón Atrás en el controlador secundario, que es la clase que se deriva de 'UIViewController'. Puedo cambiar el título del Botón Atrás pero estableciendo los valores de acción & de destino cuando se ignora la configuración del BackBarButtonItem. ¿Cuál es una forma de recibir algún tipo de notificación de que el botón Atrás fue tocado?Cómo atrapar el evento del botón Atrás
- (void)showDetailView
{
// How I'm creating & showing the detail controller
MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyDetailView" bundle:nil];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Pages"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(handleBack:)];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[self.navigationController pushViewController:controller animated:animated];
[controller release];
}
- (void)handleBack:(id)sender
{
// not reaching here
NSLog(@"handleBack event reached");
}
Para las personas que buscan una solución eficaz iOS 5+: http: // stackoverflow.com/a/13370744/1072846 – Eric