我在头文件中声明一个变量并在实现中对其进行合成。当视图加载(ViewDidLoad)时,我读取一个plist文件,用变量填充一个值。用我的NSLog我看到变量包含值。但是,在视图加载之后,我通过按钮执行一个方法来与用户进行一些交互。通过这种方法,我再次检查这个值,它是无效的。为什么变量在初始加载后不会保持其值?变量丢失其值(iPhone SDK)
program.h
....
NSString * user_title;
...
@property (nonatomic, retain) NSString *user_title;
program.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
....