0

I am pushing viewControllerB from A as,

    if(!self.controller2){

                self.controller2 = [[viewControllerB alloc] initWithNibName:@"viewControllerB" bundle:nil anUser:self.idUser aidioma:self.idioma];
            }

    [[self navigationController] pushViewController:self.controller2 animated:NO];

Then, I pop B to A. Now need to push A again but initializing again B or calling function on B in order to pass new vars. Following options could be valid but I've got no success,

  1. Release controller2 and = nil, but IF sentence is not executed because controller2 still active!
  2. Call function on viewControllerB in order to pass new pars without init but function is not called.

What am doing wrong? Thanks.

Jaume
  • 3,672
  • 19
  • 60
  • 119

2 Answers2

1

The following code ensures that every time you navigate from A -> B -> A (via the Nav Controller's back button) -> B, B's init method is called every time (I'm using ARC here... if you aren't, let me know and I'll edit the example):

AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    viewControllerA *vcA = [[viewControllerA alloc] initWithNibName:@"viewControllerA" bundle:nil];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vcA];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    return YES;
}

viewControllerA's button action method:

- (IBAction)moveForward:(id)sender {
    // change this line to call your custom init method.
    viewControllerB *vc = [[viewControllerB alloc] initWithNibName:@"viewControllerB" bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];
}
J Shapiro
  • 3,861
  • 1
  • 19
  • 29
0

Try to Use NSNotificationCenter check this Link which Describes it Properly.

Send and receive messages through NSNotificationCenter in Objective-C?

use This Code in your Class A viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(receiveTestNotification:) 
        name:@"TestNotification"
        object:nil];

Use the following Code in your Class B pop function.

 [[NSNotificationCenter defaultCenter] 
        postNotificationName:@"TestNotification" 
        object:self];
Community
  • 1
  • 1
Siba Prasad Hota
  • 4,779
  • 1
  • 20
  • 40