オブジェクトをplistファイルにアーカイブし、後でそれをロードしてtableViewを埋めようとしていました。ファイルは正しくアーカイブされているようですが、ファイルから値を取得しようとするとアクセスが悪くなります。
私は何か間違ったことをしていますか?
これは私がそれを保存する場所です
// 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 = @"christian.sandrini@example.com";
[book addObject:chris];
[chris release];
Phonebook *sacha = [[Phonebook alloc] init];
sacha.name = @"Sacha Dubois";
sacha.phone = @"079 777 777";
sacha.mail = @"info@yzx.com";
[book addObject:sacha];
[sacha release];
Phonebook *steve = [[Phonebook alloc] init];
steve.name = @"Steve Solinger";
steve.phone = @"079 123 456";
steve.mail = @"steve.solinger@wuhu.com";
[book addObject:steve];
[steve release];
[NSKeyedArchiver archiveRootObject:book toFile:@"phonebook.plist"];
そしてここで私はそれをファイルから取り出して配列に戻そうとします
- (void)viewDidLoad {
// Load Phone Book
NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:@"phonebook.plist"];
self.list = arr;
[arr release];
[super viewDidLoad];
}
セルを作ろうとする部分
- (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;
}
ここで不正アクセスエラー
現在の言語:自動; 現在objective-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行目。