ios iphone uinavigationcontroller appdelegate pushviewcontroller

ios - Intentando acceder a UINavigationController desde AppDelegate



iphone pushviewcontroller (1)

Ok, todavía soy bastante nuevo en el desarrollo de iOS, así que me disculpo si esta es una pregunta tonta.

Pero, tengo un AlertView que llamo desde AppDelegate luego respondo cuando hago clic en un botón en la alerta. Puedo hacer un NSLog y ver que se están llamando los métodos. Pero, no está empujando la vista hacia la pila. Aquí hay una muestra de lo que tengo (estoy seguro de que está mal):

Esto está en AppDelegate.m :

#import "AppDelegate.h" #import "ProfileConnection.h" @implementation AppDelegate @synthesize window = _window; @synthesize navController; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } -(void)switchToController:(NSString *)controller animated:(BOOL)animated{ NSLog(@"switching to controller %@", controller); // maybe we can do a check to see if a subview exists...and then push or pop accordingly. // switch to the "TableView" view if( [controller isEqualToString:@"ProfileConnection"]){ NSLog(@"switching to the ProfileConnection view"); ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:@"ProfileConnection" bundle:nil]; [self.navController pushViewController:profile animated:YES]; } } -(void)showConnectionFoundAlert { NSString *connectFoundMsg = [[NSString alloc] initWithFormat:@"We found someone we''d think you would like to meet: Tony Davis"]; UIAlertView *connectionFoundAlert = [[UIAlertView alloc] initWithTitle:@"Connection Found" message:connectFoundMsg delegate:self cancelButtonTitle:@"Decline" otherButtonTitles:@"Connect", @"View Profile", @"Save For Later", nil]; [connectionFoundAlert show]; //[connectionFoundAlert release]; } -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; NSString *alertString = [[NSString alloc] initWithFormat:@""]; if([title isEqualToString:@"Decline"]) { alertString = @"Declied"; } else if([title isEqualToString:@"Connect"]) { alertString = @"Connected"; } else if([title isEqualToString:@"View Profile"]) { //alertString = @"Profile Viewed"; //NSLog(@"View Profile is being called"); [self switchToController:@"ProfileConnection" animated:YES]; //UIViewController *profile = [[UIViewController alloc] initWithNibName:@"ProfileConnection" bundle:nil]; //ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:@"ProfileConnection" bundle:[NSBundle mainBundle]]; //UINavigationController *nav = [[UINavigationController alloc] init]; //[nav pushViewController:profile animated:NO]; /*UIViewController *profile = [[UIViewController alloc] initWithNibName:@"ProfileConnection" bundle:nil]; UINavigationController *navigation = [[UINavigationController alloc] init]; [navigation pushViewController:profile animated:YES];*/ /* ProfileConnection *profile = [ProfileConnection alloc]; //UIView *current = self.window; [self.window addSubview:profile.view]; */ /* [window addSubview:view1.view]; [window makeKeyAndVisible]; - (void)goToNextPage { view2 = [ViewController2 alloc]; UIView *current = self.window; [self.window addSubview:view2.view]; */ } else if ([title isEqualToString:@"Save For Later"]) { alertString = @"Saved It"; } UIAlertView *alertStr = [[UIAlertView alloc] initWithTitle:@"" message:alertString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; if ([alertString isEqualToString:@""]) { } else { [alertStr show]; } } @end

Este es el AppDelegate.h :

#import <UIKit/UIKit.h> #import "ProfileConnection.h" @interface AppDelegate : UIResponder <UIAlertViewDelegate, UIApplicationDelegate, UINavigationControllerDelegate> { UINavigationController *navController; } @property (strong, nonatomic) UIWindow *window; @property (nonatomic, retain) UINavigationController *navController; -(void)showConnectionFoundAlert; -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; -(void)switchToController:(NSString *)controller animated:(BOOL)animated; @end

Puedo agregar la vista con esto, pero pierdo mi controlador de navegación:

ProfileConnection *profile = [ProfileConnection alloc]; [self.window addSubview:profile.view];

Puedes ver que he intentado algunos enfoques, pero me estoy confundiendo tratando de usar el enfoque del guión gráfico.

Además, la vista de ProfileConnection está en blanco con una sola etiqueta en este momento, si eso ayuda.


Tu código se ve bien [self.navController pushViewController:profile animated:YES]; es cómo deberías hacerlo.

Debe asegurarse de haber agregado el controlador de navegación a la ventana. Quizás esto ya debería ser hecho por el guión gráfico, pero si no se usa la propiedad rootviewcontroller de la ventana (es mejor que addSubview ).

self.window.rootViewContorller = self.navController;

Ahora haga una verificación de cordura para asegurarse de que nada sea nulo ( profile o navController ).

NSLog(@"%@ %@",self.navController, profile);

¿Algo de eso ayuda?