0
我正在與Core Data
一起工作,我希望你能幫我解決我遇到的問題。這個例子是假設我有3個實體Make和Model,Options和具有多個屬性的汽車圖像。每個選項可以有1個Make,多個選項和1個圖像。我想要發生的是,如果只有一個選項,則跳過深入查看選項並直接轉到圖像。實例是:核心數據鑽取表
Table of more than one Option
make - Model | Options | Photo
Chevy Camaro -> LS -> Image of Car.
Chevy Camaro -> LT -> Image of Car.
table of one Option
Chevy Blazer -> Image of Car
這是我預想中做
這是if語句
if(options > 1 || count.totalCount == 0)
{
//
[self performSegueWithIdentifier:@"multipleDetails" sender:self];
}else
{
[self loadImage];
Image *link = [_urlFetchedResultsController objectAtIndexPath:indexPath];
webViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"webView"];
detailViewController.webData = link.link;
[self.navigationController pushViewController:detailViewController animated:YES];
}
,這是獲取數據的一部分。
- (void)loadMakeModel {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"MakeModel" inManagedObjectContext:localContext]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(make == %@)",currentMake];
[fetchRequest setPredicate: predicate];
//NSLog(@"fetch request: %@",fetchRequest);
[fetchRequest setFetchBatchSize:40];
NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"Model" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortByName]];
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:localContext sectionNameKeyPath:nil cacheName:nil];
[_fetchedResultsController performFetch:nil];
}
- (void)loadOptions {
[self loadMakeModel];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
optionTitle = [_fetchedResultsController objectAtIndexPath:indexPath];
NSString *options = [MakeModel MR_findFirstByAttribute:@"OptionTitle" withValue:optionTitle.makeTitle];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"FCOptions" inManagedObjectContext:localContext]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(options == %@)",options];
//
[fetchRequest setPredicate: predicate];
NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortByName]];
_optionsFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:localContext sectionNameKeyPath:nil cacheName:nil];
[_optionsFetchedResultsController performFetch:nil];
}
- (void)loadImage {
[self loadOptions];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ImageUrl = [_optionsFetchedResultsController objectAtIndexPath:indexPath];
//
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"CarImage" inManagedObjectContext:localContext]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(url == %@)",ImageUrl.url];
//
[fetchRequest setPredicate: predicate];
NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"url" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortByName]];
_urlFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:localContext sectionNameKeyPath:nil cacheName:nil];
[_urlFetchedResultsController performFetch:nil];
}
問題是由於某種原因,optionTitle
是零。 任何幫助或例子,將不勝感激。
什麼是芯片問題是什麼?可能你最好展示一些代碼。 –