【发布时间】:2012-05-25 01:56:04
【问题描述】:
我只是不明白.. 这种情况到处发生,但我找不到任何理由或理由。 我已经搜索了一段时间没有运气..也许你们可以告诉我我做错了什么?
我正在 ViewController_B 中的 ViewController_A 中设置一个 BOOL。 单步执行代码,我看到 BOOL 变为 YES,但是当我被发送回 VC_A 时,它又变为 NO
更新:这一切都在主线程上。
这是我的代码。
ViewController_A.h
BOOL shouldLogin;
@property(nonatomic,assign)BOOL shouldLogin;
ViewController_A.m
@synthesize shouldLogin;
//in viewWillAppear of ViewController_A
if (shouldLogin == YES) {
//do something - im trying to get in here but I cant because the BOOL is NO when I come back to this view
}
这是我在 ViewController_B 中设置 BOOL 的方式
ViewController_A * vc = [[ViewController_A alloc]init];
vc.shouldLogin = YES;
//stepping through the code and looking at the value, shouldLogin shows YES
[self dismissModalViewControllerAnimated:YES]; // this drops down VC_B which will show VC_A
//now VC_A just came into view and the BOOL is now NO which makes the compiler skip over my IF statement
更新:删除了我的发布调用,但仍然是同样的问题。
【问题讨论】:
-
嗯..什么?我错过了什么吗?你分配
vc,然后将shouldLogin 设置为YES,然后立即通过发送release消息释放它... -
抱歉,我应该提一下,我尝试了使用该版本和不使用该版本。我在发布这个问题时把它留在了那里,但它没有任何区别..它仍然无法工作。
-
不管有没有
release,它都不起作用,因为您在ViewController_B中创建的ViewController_A与已经实例化的ViewController_A不同。