NSCFConstantString text]:发送到实例的无法识别的选择器

时间:2017-01-06 08:18:59

标签: objective-c

  

NSCFConstantString text]:发送到实例的无法识别的选择器

NSManagedObjectContext *context = [self managedObjectContext];

if (self.device) {
    // Update existing device
    [self.device setValue:self.nameTextField.text forKey:@"name"];
    [self.device setValue:self.versionTextField.text forKey:@"version"];
    [self.device setValue:self.companyTextField.text forKey:@"company"];
    NSLog(@"if");
} else {
    // Create a new device
    NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Device" inManagedObjectContext:context];
    [newDevice setValue:self.nameTextField.text forKey:@"name"];
    [newDevice setValue:self.versionTextField.text forKey:@"version"];
    [newDevice setValue:self.companyTextField.text forKey:@"company"];
    NSLog(@"else");
}

NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
    NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}

1 个答案:

答案 0 :(得分:0)

  

NSCFConstantString text]:发送到实例的无法识别的选择器

错误表明您尝试在text上设置NSString

因此,检查您的代码并查看是否要访问text上的NSString属性,因为NSString没有text属性并更正了。

希望这会有所帮助!