我正在从A 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上调用函数以传递新的变量。以下选项可能有效,但我没有成功,
出错了什么?感谢。
答案 0 :(得分:1)
以下代码可确保您每次从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;
}
viewControllerA的按钮操作方法:
- (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];
}
答案 1 :(得分:0)
尝试使用NSNotificationCenter
check this Link正确描述它。
Send and receive messages through NSNotificationCenter in Objective-C?
在A类viewDidLoad
中使用此代码:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"TestNotification"
object:nil];
在B类弹出功能中使用以下代码。
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];