2012-01-17 96 views
0

我在ViewController上有一個選擇器,並將結果打印在標籤上。我有保存這些結果爲CoreData一個問題,得到一個錯誤代碼將UILabel結果保存到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]; 
} 

爲什麼會造成錯誤?預先感謝您的意見。

回答