Search code examples
iphoneiosxcodezbar-sdk

error to segue from ZBar to another view


will like to know how to fix this error.

i will

  QRReader = [ZBarReaderViewController new];
  [self presentViewController:QRReader animated:YES completion:nil];

in customoverlay i have a button that will call

 [helpButton addTarget:self action:@selector(goToTips) forControlEvents:UIControlEventTouchUpInside];

-(void)goToTips
{
    [QRReader performSegueWithIdentifier:@"scannerToTips" sender:self];
}

but when i pressed the button i will get this error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<ZBarReaderViewController: 0x3c5350>) has no segue with identifier 'scannerToTips''

Solution

  • Ok there are some issues with the code...

    1. Seques is a feature that must be used in iOS5 (and later) and only if you choose storyboards instead of xibs
    2. If you indeed use a seque, you must define an identifier in Interface Builder by clicking on your seque and typing an identifier name in the inspector
    3. A seque is automatically instantiating your destination controller, so you do not have to do so manually

    So a proper call to seque would be:

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        ZBarReaderViewController *QRReader = [segue destinationViewController];
        // So to hold a reference and pass any data
    }
    

    But in your case I'm guessing that you are not using a segue... So a code like this would be fine:

    [helpButton addTarget:self action:@selector(goToTips) forControlEvents:UIControlEventTouchUpInside];
    
    -(void)goToTips
    {
      QRReader = [ZBarReaderViewController new];
      [self presentViewController:QRReader animated:YES completion:nil];
    }
    

    I hope that this helped...