2017-01-06 75 views
0

NSCFConstantString文本]:無法識別的選擇發送到實例NSCFConstantString文本]:無法識別的選擇發送到實例

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

你從哪裏得到錯誤?請正確格式化您的代碼。 – mattsson

回答

0

NSCFConstantString文本]:無法識別的選擇發送到實例

錯誤建議您在NSString上嘗試設置text

因此,請檢查您的代碼,看看是否正在訪問text屬性NSString,因爲NSString沒有text屬性並將其更正。

希望這會有所幫助!

相關問題