Detection when nav controller popped up on root

Here is my code:

SignupController* signupController = [[SignupController alloc] initWithNibName:@"SignupController" bundle:nil]; [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; self.navigationController.title = @"MyNavController"; [self.navigationController pushViewController:signupController animated:YES]; [signupController release]; 

Unfortunately, for me, the call to pushViewController is not synchronous, so the next line ([signupController release]) is executed immediately.

I need to find that signupController is back to the root, so I can take data from the registration controller and make a registration or login.

Any ideas?

thanks

+4
source share
4 answers

Use the delegate template to call back to the main controller to tell him that the registration controller is about to exit. Copy the values ​​from the registration controller before it is released by the navigation controller.

 // SignupController.h @protocol SignupDelegate; @interface SignupController : UIViewController { id <SignupDelegate> delegate; NSString *name; } @property (nonatomic, assign) id <SignupDelegate> delegate; @property (nonatomic, retain) NSString *name; @end @protocol SignupDelegate - (void) signupControllerDidFinish:(SignupController *)controller; @end // SignupController.m @implementation SignupController @synthesize delegate; @synthesize name; - (void) viewWillDisappear:(BOOL)animated { [self.delegate signupControllerDidFinish:self]; } @end // YourViewController.m - (void) signupSelected { SignupController *signup = [[SignupController alloc] initWithNibName:NSStringFromClass([SignupController class]) bundle:nil]; signup.delegate = self; [controller.navigationController pushViewController:signup animated:YES]; [signup release]; } - (void) signupControllerDidFinish:(SignupController *)signup { NSLog(@"Signup with name %@", signup.name); } 
+4
source

Register in -viewWillDisappear: in your RegistrationController account. But you cannot stop the controller from disappearing if the input fails.

Instead, you can imagine RegistrationController as a model view manager where the back button is no longer automatically displayed, so you can control when to leave this page.

+2
source

There are several ways to do this:

  • Pass the UINavigationController delegate and answer the delegate to navigationController:willShowViewController:animated: In this method, verify and verify whether the displayed display controller should be the first view controller in the array of the navigation controller viewControllers . This has the disadvantage of being unable to distinguish between a popToRoot and a simple reverse action.
  • Subclass UINavigationController and override the popToRoot method:

      - (NSArray *) popToRootViewControllerAnimated: (BOOL) animated {
       // somehow notify (NSNotification, delegate, etc) that you're popping to root
       return [super popToRootViewControllerAnimated: animated];
     } 
  • viewWillAppear method to your root controller. This has the disadvantage that you cannot distinguish between the initial push, a popToRoot and the simple reverse action.

+1
source

Not sure if I understood your question ...

But if I ... why not use BOOL isSigningUp.

In your root, in ViewDidLoad, you assign it NO.

When you click your signupController, you assign BOOL to YES.

Then, in the root view of WillAppear, you put ...

 if (isSigningUp == YES) { isSigningUp = NO; //do registration or login } 

This is easy, which means that I probably did not understand what you asked. If this is the case, sorry for not taking your time.

All the best.

0
source

Source: https://habr.com/ru/post/1304005/


All Articles