Search code examples
iosstoryboardxcode4.5zbar-sdkuitabcontroller

change view (storyboard) after zbar didFinishPickingMediaWithInfo inside a tab


I'm still new to programming on the iPhone, and have researched my problem, but have no luck with any of the solutions.

I have managed to follow ZBar SDK Integration tutorial to have a working app at the end, inside a tab controller.

What I am trying to do is, move the results to a separate ViewController.

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;

    ProductViewController *product = [self.storyboard instantiateViewControllerWithIdentifier: @"ProductView"];

    product.resultImage = [info objectForKey: UIImagePickerControllerOriginalImage];
    product.resultText = symbol.data;

    [reader dismissModalViewControllerAnimated:YES];
    [self presentModalViewController:product animated:YES];
}

The problem I'm having with the code is that product view controller never displayed.

Using Xcode 4.5, iOS 6 SDK.


Solution

  • I ended up abandoning the above approach and instead added function on my navigigation controller to handle displaying.

    Displaying Scan:

    [[self targetController] displayNewObject:scan];

    On the receiving end:

    - (void)displayNewObject:(_Scan *)scan
    {
        self.scan = scan;
        self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
        [[self navigationController] popToRootViewControllerAnimated:NO];
        [self performSegueWithIdentifier: @"ShowScanDetail" sender: self];
        self.scan = nil;
    }