Question

Here is my Story Board and the homeSegue Identifier :

Story Board .. Segue Identifier is highlighted

Here is the code block from where i am getting back to the previous 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];

    }

}

It's returning me to the ScanProductViewController. But When i am trying to click the search button again from the ScanProductViewController I am getting the following exception :

 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   

Please suggest me how can i return to ScanViewController without changing it's previous behaviour.

Thanks

Here is the method in which it's crashing .. Please suggest :

-(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;

}

Was it helpful?

Solution 2

I think there is not a problem with segue.Problem is with coredata that you are searchin for entity name as product i think in this line

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

but in your coredata file there is nor exist any Entity name as "product" so that,s problem.

OTHER TIPS

It is strange that you use push segue to popToRootViewController. It doesn't need segue to pop or back to previous view controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top