ios - 将 UILabel 结果保存到 CoreData 中

标签 ios core-data save

我在 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/

相关文章:

iphone - 反向关系警告 - 询问使用反向关系的实践

java - 在java中序列化数组列表

xcode - 重命名 XCode 项目,现在应用程序将无法加载

ios - NSURLSession 生命周期和基本授权

ios - 执行drawAtPoint时如何指定图像尺寸/大小?

ios - 忽略 NSURLErrorDomain 错误 -999 在 UIWebView 中不起作用

objective-c - 语言速度 c vs objective c

ios - Weirdcore 数据 react - 未检测 NSManagedObject 子类

objective-c - 核心数据批量插入突然减慢到速度的 1/10

java - 如何将Stanford nlp中的CoreDocument保存到磁盘