我试图将一个对象归档到一个 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 行。