我在 ViewController
上有一个选择器,结果打印在标签上。我在将这些结果保存到 CoreData
时遇到问题,收到错误代码
"[<__NSCFConstantString 0xf488> valueForUndefinedKey:]: this class is not key value coding-compliant for the key attribute.'.
以下是打印标签的代码:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
mlabel.text= [arrayNo objectAtIndex:row];
}
以下是将标签结果保存到核心数据的代码:
- (IBAction)editSaveButtonPressed:(id)sender
{
if (!currentCategory)
self.currentCategory = (Entity *)[NSEntityDescription insertNewObjectForEntityForName:@"Entity" inManagedObjectContext:self.managedObjectContext];
[self.currentCategory setAttribute:[mlabel text]]; //This is the line causing the error
NSError *error;
if (![self.managedObjectContext save:&error])
NSLog(@"Failed to add new category with error: %@", [error domain]);
[self.navigationController popViewControllerAnimated:YES];
}
为什么会导致错误?预先感谢您的意见。
最佳答案
看起来 Entity
上没有定义 attribute
属性(因此 setAttribute
)。
您可能想查看有关核心数据的教程:http://www.raywenderlich.com/934/core-data-tutorial-getting-started
关于ios - 将 UILabel 结果保存到 CoreData 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888238/