У мене два сутності: Пункт і Примітка.
призначити зв'язок під час збереження
Item *item = [NSEntityDescription insertNewObjectForEntityForName:@"Item"
inManagedObjectContext:self.managedObjectContext];
Note *note = [NSEntityDescription insertNewObjectForEntityForName:@"Note"
inManagedObjectContext:self.managedObjectContext];
note.noteText = @"test";
[note setInItem:item]; //set relationship??
[self.managedObjectContext save:nil]; // write to database
Коли я завантажу дані, завантажуються атрибути Item, але я не знаю, як завантажувати note.noteText для цього елемента.
self.itemNameTextField.text = self.item.name;
...
...
self.itemNoteTextField.text = ????????????
Дякую!
Відповіді:
1 для відповіді № 1Якщо item
є Пункт об'єкт тоді item.containNote
є сукупністю всіх споріднених Примітка об'єктів. Ви можете переглядати нотатки
for (Note *note in item.containNote) {
NSString *text = note.Text;
// Now you can create a text field for this note and display the text ...
}