我在搜索部分遇到错误。当我输入歌曲名称时,我应该在那里得到歌词但是收到错误说'executeFetchRequest:错误:获取请求必须有一个实体。'我使用了以下代码
-(void)findLyrics
{
LyricsAppDelegate *appDelegate = [[UIApplication sharedApplication]
delegate];
NSManagedObjectContext *managedObjectContext = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription
entityForName:@"Lyrics"inManagedObjectContext:managedObjectContext];
NSManagedObject *LyricsObjectEnglish;
LyricsObjectEnglish = [NSEntityDescription insertNewObjectForEntityForName:@"English_Songs"
inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDesc];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(MovieSongName = %@)",song_name.text];
[request setPredicate:pred];
NSManagedObject *matches = nil;
NSError *error;
NSArray *objects = [managedObjectContext executeFetchRequest:request error:&error];
if ([objects count] == 0)
{
//status.text = @"No matches";
} else {
matches = [objects objectAtIndex:0];
song_lyrics.text = [matches valueForKey:@"SongLyrics"];
song_name.text = [matches valueForKey:@"MovieSongName"];
// status.text = [NSString stringWithFormat:@"%d matches found", [objects count]];
}
[request release];
}
任何身体请帮助..