헤더 파일에 변수를 선언하고 구현시 합성합니다. 보기가로드 될 때 (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
....