Cómo subclasificar UINavigationController
Necesitaba reproducir un sonido cuando el usuario le daba al botón superior izquierdo de un UINavigationController. Es decir, el botón de «patrás» (en términos tésnicos).
Primer intento: Hay delegates pa tó
La primera sospecha, fue buscar algún delegate, ya que como bien dijo el filósofo español «Rafael Guerra»: en Cocoa hay delegates pa tó.
En efecto, UINavigationController tiene un delegate: UINavigationControllerDelegate. Lamentablemente, el protocolo del delegate nos es muy completo que digamos y consiste en los siguientes mensajes:
– navigationController:willShowViewController:animated: – navigationController:didShowViewController:animated:
Sin embargo, lo que necesito yo NO es saber cuando va a enseñar un nuevo ViewController, sino justo lo contrario, cuando va a hacer un popViewController.
Segundo intento: Cuando todo falla, subclasifica
La solución era evidente y muy sencilla: crear una subclase de UINavigationController.
Interfase
#import
@interface FRRNavigationController : UINavigationController {
}
@end
Implementación
#import "FRRNavigationController.h"
#import "FRRUXSounds.h"
@implementation FRRNavigationController
-(UIViewController *) popViewControllerAnimated:(BOOL)animated{
[[FRRUXSounds defaultSounds] backClick];
return [super popViewControllerAnimated:animated];
}
@end
