전역으로 정의되고 UITableViewController의 ViewDidLoad에서 초기화되는 클래스 인스턴스가있는 iPhone 애플리케이션에서 작업합니다.Objective C 클래스 인스턴스 속성이 UITableViewController에서 할당 취소
cellForRowAtIndexPath에 도달하면 인스턴스 속성이 할당 취소되고 디버거처럼 나타납니다.
속성이 데이터베이스에서로드되고 있습니다.
Foo.h
NSString *prop1;
@property(nonatomic, retain)NSString *prop1;
-(void)shouldLoadProperties;
Foo.m
@synthesize prop1;
-(void)shouldLoadProperties {
<FMDatabase stuff here>
FMResultSet *rs = [self executeQuery:sql];
prop1 = [rs stringForColumn:@"col1"]; //loads db value "Test" into prop1
}
의 tableview 컨트롤러 :
TestTableViewController.h
Foo *foo;
TestTableViewController.m 내가 foo는 공개하고 있지 않다
-(void)viewDidLoad {
foo = [[[Foo alloc] init] retain];
[foo shouldLoadProperties];
//Breakpoint here shows that foo.prop1 is set to "Test"
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//foo is is still allocated, but foo.prop1 has been
//deallocated; shows as <freed object>
NSLog(@"Prop 1 is %@", foo.prop1); //throws exception
}
때문에 특성이 스스로 이유를 할당을 취소 것인가? 인스턴스가 출시 될 때까지 속성에 매달려있는 Foo에서 뭔가가 누락 되었습니까?
UPDATE는
나는 발견 데이터베이스에서 속성을 채우는 경우 데이터를 보관 유지하는, 유지 추가하여 :
prop1 = [[rs stringForColumn:@"col1"] retain];
이 맞거나 내가 다른 뭔가를 놓친 거지?
우수. 답변 해 주셔서 감사합니다. – jfuhr