Search code examples
iphonepresentmodalviewcontrollerzbar-sdk

trying to show a new screen after image is scanned


I am running into an issue that seems so simplistic, is frustrating. I am using the zbar library to play around with scanning qr-codes. Here is my code:

- (IBAction)scanButtonTapped:(id)sender {

// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.showsZBarControls = NO;

UIButton *overlay = [UIButton buttonWithType:UIButtonTypeCustom];
overlay.frame = CGRectMake(0, 0, 320, 480);
[overlay setImage:[UIImage imageNamed:@"CameraCover.png"] forState:UIControlStateNormal];
reader.cameraOverlayView = overlay;

overlay.userInteractionEnabled = YES;
[overlay addTarget:self action:@selector(beginScanning:) forControlEvents:UIControlEventTouchUpInside];




ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here

// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];

// present and release the controller
[self presentModalViewController: reader
                        animated: NO];
[reader release];



}

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

// EXAMPLE: do something useful with the barcode data
resultText.text = symbol.data;

// EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];


// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];

[self pushNewScreen];

}

-(void) pushNewScreen
{
MainViewController *mainView = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
[self presentModalViewController:mainView animated:YES];
[mainView release];
}

The problem is, when pushNewScreen is called, mainView is not shown... I have gone through each line with the debugger and every line in pushNewScreen is called. Any ideas?


Solution

  • Thanks to A-Live, I was able to solve it using

    - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion 
    

    instead. Hope this helps someone else!