2010-05-18 4 views
2

개체를 plist 파일에 보관하고 나중에 tableView를 채우기 위해로드하려고했습니다. 파일이 올바르게 보관 된 것으로 보이지만 파일에서 값을 가져 오려고 할 때 잘못된 액세스가 발생합니다.NSKeyedUnarchiver - 액세스 권한이 잘못되었습니다

내가 잘못 했나요?

이 내가 내가 빌드 할 경우

- (void)viewDidLoad { 
    // Load Phone Book 
    NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:@"phonebook.plist"]; 

    self.list = arr; 

    [arr release]; 
    [super viewDidLoad]; 
} 

부분 파일에서 그것을 얻을 배열로 다시 저장하려고 여기

// Create some phonebook entries and store in array 
NSMutableArray *book = [[NSMutableArray alloc] init]; 
Phonebook *chris = [[Phonebook alloc] init]; 
chris.name = @"Christian Sandrini"; 
chris.phone = @"1234567"; 
chris.mail = @"[email protected]"; 
[book addObject:chris]; 
[chris release]; 

Phonebook *sacha = [[Phonebook alloc] init]; 
sacha.name = @"Sacha Dubois"; 
sacha.phone = @"079 777 777"; 
sacha.mail = @"[email protected]"; 
[book addObject:sacha]; 
[sacha release]; 

Phonebook *steve = [[Phonebook alloc] init]; 
steve.name = @"Steve Solinger"; 
steve.phone = @"079 123 456"; 
steve.mail = @"[email protected]"; 
[book addObject:steve]; 
[steve release]; 

[NSKeyedArchiver archiveRootObject:book toFile:@"phonebook.plist"]; 

를 저장하고있는 곳입니다 세포

다음
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *PhoneBookCellIdentifier = @"PhoneBookCellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PhoneBookCellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:PhoneBookCellIdentifier] autorelease]; 
    } 

    NSUInteger row = [indexPath row]; 
    Phonebook *book = [self.list objectAtIndex:row]; 
    cell.textLabel.text = book.name; 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

    return cell; 
} 

나쁜 액세스 오류

현재 언어 : 자동; 현재 목표 - C 어설 션 실패 : (CLS), 기능 getName, 파일 /SourceCache/objc4_Sim/objc4-427.5/runtime/objc-runtime-new.mm, 라인은 3990 어설 션 실패 : (CLS), 기능을 getName, /SourceCache/objc4_Sim/objc4-427.5/runtime/objc-runtime-new.mm 파일, 라인은 3990 어설 션 실패 : (CLS), 기능 getName, /SourceCache/objc4_Sim/objc4-427.5/runtime 파일 /objc-runtime-new.mm, 라인 3990 어설 션 실패 : (CLS), 기능 getName, 파일 /SourceCache/objc4_Sim/objc4-427.5/runtime/objc-runtime-new.mm, 라인 3990

+0

I을 이것이 유일한 문제인지 확실하지 않지만 viewDidLoad에서 arr을 해제해서는 안됩니다. – walkytalky

답변

2

그냥 그 부분을 확장하려면 unarchiveObjectWithFile이 자동으로 해제 된 포인터를 반환합니다. 당신은 국부적으로 retain이 아니므로 release이 아니어야합니다. 당신이하기 때문에, 그 객체는 나중에 할당 해제되고 book.name을 호출하여 사용할 때까지는 거기에 존재하지 않습니다.

(I 개체가 같은 당신이 여기에 공개하지 않는 주위에 보관됩니다. 그렇지 않으면, 당신은 그것도 해결해야합니다 있도록 self.list 속성을 적절하게 유지되어 있으리라 믿고있어.)

+0

당신은 남자입니다 ;-) [arr release]를 제거하면 문제가 해결됩니다. 고마워요! – Chris

+0

이 답변으로 하루가 절약되었습니다 - 감사합니다! – Micko

관련 문제