【发布时间】:2012-11-22 05:44:30
【问题描述】:
我检查了这里关于堆栈溢出的问题,我用同样的方式做,但仍然返回 NULL
在第一个视图中
在 firstviewcontroller.h 我有
@property (nonatomic, copy) NSString *Astring;
在firstviewcontroller.m中
#import "SecondViewController.h"
...
@synthesize Astring = _Astring;
...
- (IBAction)filterSearch:(id)sender {
NSlog(@"%@",Astring)
}
在第二个viewcontroller.m中
#import firstviewcontroller.h
...
...
FirstViewController *controller = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
controller.Astring = @"YES";
所以基本上我在 firstviewcontroller 中创建一个变量,然后在 secondviewcontroller 中将变量传递给第二个视图,但它总是返回 NULL...
是我的逻辑错了还是其他原因
【问题讨论】:
-
您的#import 有问题,您似乎将它们倒置了。它不会纠正问题,但问题会更容易理解。
-
在 NSLog 中尝试 self.Astring 而不是 Astring
-
@Yarlik 2bad 它仍然是 NULL
-
除此之外,总是需要创建一个变量并将变量传递给它......你不能在另一个视图中看到它吗?
-
您的代码令人困惑。您声明了一个名为“AString”的属性,然后将其合成,将“_Astring”分配为实例变量。在 SecondViewController 中,您将值 @"YES" 设置为属性,但在 NSLog() 中的 filterSearch 方法中,您使用不同的变量“Astring”,它不是属性或相应的实例变量。您是否在某处也有一个“Astring”变量,或者它只是一个错字?