我有一些问题如何实现从选定的数据库及其属性组创建新视图。在我的应用程序中,所有资源(数据)都显示在 mainviewController.xib 中。在第二个 viewController 中,我有文本字段可以将数据添加到我的基础中。在这个文本字段中是组。当我向我的基地写一个新组时,我想添加新视图。当我的组名与我实际基地中的组名相同时,我什么也不做。在这里,我给出了一些我使用的代码。在我的代码中,grupa 作为组。此代码来自第二个视图。
- (IBAction) saveData
{
NSLog(@"saveData");
[self dismissKeyboard];
Destination *dest = (Destination *)[NSEntityDescription insertNewObjectForEntityForName:@"Destination"
inManagedObjectContext:managedObjectContext];
dest.nazwa = nazwaTextField.text;
dest.zasob = zasobTextField.text;
dest.grupa = grupaTextField.text;
dest.typzasobu = typzasobuTextField.text;
dest.tag = [NSNumber numberWithInt:[_arrayLogics indexOfObject:typzasobuTextField.text]];
NSError *error;
// here's where the actual save happens, and if it doesn't we print something out to the console
if (![managedObjectContext save:&error])
{
NSLog(@"Problem saving: %@", [error localizedDescription]);
}
// **** log objects currently in database ****
// create fetch object, this object fetch's the objects out of the database
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Destination" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects)
{
NSLog(@"Nazwa Zasobu: %@", [info valueForKey:@"nazwa"]);
NSLog(@"Zasób: %@", [info valueForKey:@"zasob"]);
NSLog(@"Grupa: %@", [info valueForKey:@"grupa"]);
NSLog(@"Typ zasobu: %@", [info valueForKey:@"typzasobu"]);
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Potwierdzenie" message:@"Zasób zapisany" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
谢谢