Segue Identifier Crash Issue

时间:2014-05-03 10:07:52

标签: ios storyboard

这是我的故事板和homeSegue标识符:

Story Board .. Segue Identifier is highlighted

这是我回到上一个viewController的代码块:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


    if([segue.identifier isEqualToString:@"homeSegue"]){
        ProductScannerViewController *product_scannerViewController = segue.destinationViewController;
        product_scannerViewController.delegate=self;

    }

    if([segue.identifier isEqualToString:@"scanSegue"]){

        [self.navigationController popToRootViewControllerAnimated:YES];

    }

}

它将我带回ScanProductViewController。但是,当我尝试再次从ScanProductViewController单击搜索按钮时,我收到以下异常:

 2014-05-03 16:05:51.349 Spisrett[5239:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Product''
*** First throw call stack:
(
    0   CoreFoundation                      0x021d71e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib   

请建议我如何在不改变之前行为的情况下返回ScanViewController。

由于

这是崩溃的方法..请建议:

-(void) configureFetchedResultsController:(NSString *) tableType;
 {
  //NSLog(@"This is the table tyoe");
  //NSLog(tableType);

tableType=@"Product";
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription 
                               entityForName:tableType inManagedObjectContext:self.context];
[fetchRequest setEntity:entity];
//Sorted by -Ishtiak
NSString *sortColumn=@"productTitle";



//actual sort.....  decidedShortingColumn


NSSortDescriptor *sort = [[NSSortDescriptor alloc]
                          initWithKey:sortColumn ascending:YES];


[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];

NSFetchedResultsController *theFetchedResultsController = 
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                        managedObjectContext:self.context
                                        sectionNameKeyPath:nil 
                                               cacheName:nil];

fetchedResultsController = theFetchedResultsController;
fetchedResultsController.delegate = self;

}

2 个答案:

答案 0 :(得分:3)

将pop segue用于popToRootViewController很奇怪。它不需要segue来弹出或回到以前的视图控制器。

答案 1 :(得分:2)

我认为segue.Problem与coredata没有问题,你正在搜索实体名称作为产品我想在这一行

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"product" inManagedObjectContext:appDelegateSharedObject.managedObjectContext];

但是在您的coredata文件中,也没有任何实体名称作为“产品”,因此,s问题。