0
我的应用程序使用核心数据存储由用户标记的书籍的信息时遇到一些困难。 它目前将这些信息保存到一个xml文件(没有核心数据),我不确定如何将其转换为使用核心数据。使用XCode的iOS 8.0应用程序的核心数据
到目前为止,我有这在我的AppDelegate.m
// Create Managed Object
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:self.managedObjectContext];
[[self managedObjectContext] save:nil];
的话,我想使用我所创建的实体被称为“相册”,哪些是“ALBUMNAME”实体中的属性和“albumArtist”两“串”
这是在代码中TableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (searching) {
// use for interaction with search list
NSDictionary *tune = [searchResults objectAtIndex:[indexPath row]];
//check label for system messages
if ([[tune valueForKey:@"mbid"] intValue] != -1) {
//Add the new album to your list
[albums addObject:tune];
// clear the search text
[searchBar setText:@""];
//Remove the cancel/done button from navigation bar
[[self navigationItem] setRightBarButtonItem:nil];
[[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];
//clear the search results and reset state
searching = NO;
[searchResults removeAllObjects];
//trying to use core data here to store the row selected by the user
[(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
// step 1 - Create new NSManagedObject for your CoreData model
// step 2 - Set values for its attributes
[newAlbum setValue:name.varchar forKey:@"name"];
[newAlbum setValue:artist.varchar forKey:@"artist"];
// step 3 - Save NSManagedContext
// step 4 - Update your list of object in 'albums' for the table view.
//force the table to reload and redraw
[[self tableView] reloadData];
/*
//Sort albums
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[albums sortUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
// this was the original method for Storing data
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *yourArrayFileName = [documentsDirectory stringByAppendingPathComponent:@"albums.xml"];
[albums writeToFile:yourArrayFileName atomically:YES];
*/
}
} else {
// use for interaction with album list
NSDictionary *tune = [albums objectAtIndex:[indexPath row]];
FilmDetailViewController *vc = [[FilmDetailViewController alloc]
initWithNibName:@"FilmDetailViewController" bundle:nil];
[vc setTune:tune];
[[self navigationController] pushViewController:vc animated:YES]; //slides the view in from the right
}
}
我试图勾勒出我需要采取的步骤,但不知道从哪里开始。任何帮助将非常感激。 :)
您缺少如何使用核心数据的基础知识。这不是一个教程网站,虽然迷你教程可能会导致SO问题。首先,阅读有关如何使用核心数据的文档。 Apple在这方面有非常好的文档,你可以通过在Xcode中使用帮助来找到它的大部分内容。还有一些非常好的书籍和教程可用。谷歌应该为你提供超过你的要求。最后,一旦你研究了基本知识,请回答你可能有的任何具体问题。 – 2015-02-24 14:09:29