我在头文件中声明了一个变量,并在实现中综合了它。当视图加载(ViewDidLoad)时,我读取了一个 plist 文件并用一个值填充变量。通过我的 NSLog,我看到该变量包含该值。但是,在视图加载后,我通过执行方法的按钮与用户进行了一些交互。在该方法中,我再次检查该值,但它是无效的。为什么变量在初始加载后不会保持其值?
程序.h
....
NSString * user_title;
...
@property (nonatomic, retain) NSString *user_title;
程序.m
@synthesize user_title;
-(void)viewDidLoad{
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
user_title = [array objectAtIndex:0];
[array release];
}
....
-(IBAction)user_touch_screen:(id)sender
{
user_label.text = user_title; //user_title has an invaliud value at this point
....