Iphone 带有自定义初始化数据的xcode pushviewcontroller

Iphone 带有自定义初始化数据的xcode pushviewcontroller,iphone,objective-c,ios,xcode,cocoa-touch,Iphone,Objective C,Ios,Xcode,Cocoa Touch,我正在从as推viewControllerB if(!self.controller2){ self.controller2 = [[viewControllerB alloc] initWithNibName:@"viewControllerB" bundle:nil anUser:self.idUser aidioma:self.idioma]; } [[self navigationController] push

我正在从as推viewControllerB

    if(!self.controller2){

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

    [[self navigationController] pushViewController:self.controller2 animated:NO];
然后,我将B弹出到A。现在需要再次按下A,但再次初始化B或调用B上的函数,以便传递新的变量。以下选项可能有效,但我没有成功

  • 释放controller2并=nil,但若由于controller2仍处于活动状态而未执行语句,则释放controller2并=nil
  • 调用viewControllerB上的函数,以便在不初始化的情况下传递新PAR,但未调用该函数

  • 我做错了什么?谢谢。

    尝试使用适当描述它的
    NSNotificationCenter

    在类A中使用此代码viewDidLoad

    [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(receiveTestNotification:) 
            name:@"TestNotification"
            object:nil];
    
    在B类pop函数中使用以下代码

     [[NSNotificationCenter defaultCenter] 
            postNotificationName:@"TestNotification" 
            object:self];
    

    下面的代码确保每次从A->B->A(通过导航控制器的后退按钮)->B导航时,每次都会调用B的init方法(我在这里使用ARC…如果没有,请告诉我,我将编辑示例):

    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;
    }
    
    - (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];
    }
    
    viewControllerA的按钮操作方法:

    - (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;
    }
    
    - (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];
    }