zbar中的取消按钮操作显示空白视图

时间:2013-12-13 10:52:07

标签: ios zbar-sdk

我在iOS应用中使用标签栏。当我点击扫描选项卡时,我调用了委托方法立即在扫描选项卡上启动摄像头。当我启动相机扫描QR码并在扫描前点击取消按钮时,我得到空白视图。如何在取消相机时显示视图

- (void) openCameraScanner
{
    ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;
    reader.showsZBarControls = YES;

    ZBarImageScanner *scanner = reader.scanner;
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    [self presentViewController:reader animated:YES completion:nil];
    reader.showsZBarControls = YES;
    //reader.cameraOverlayView = [self commonOverlay];
}

- (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
    //resultsView.text = symbol.data;
    NSString *urlString = symbol.data;
    NSURL *url = [NSURL URLWithString:urlString];
    NSLog(@"Query after scan = %@", [url query]);

    //Extract id from URL which is there in QR Code --- start
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    for(NSString *param in [urlString componentsSeparatedByString:@"&"])
    {
        NSArray *elements = [param componentsSeparatedByString:@"="];
        if([elements count]<2)
            continue;
        [dictionary setObject:[elements objectAtIndex:1] forKey:[elements objectAtIndex:0]];
        NSLog(@"value is == %@", [elements objectAtIndex:1]);
    //Extract id from URL which is there in QR Code --- end

        if([[elements objectAtIndex:1] intValue])
        {
            NSUserDefaults *defaultsForAsk = [NSUserDefaults standardUserDefaults];
            idToAsk = [NSString stringWithFormat:@"%d",[[elements objectAtIndex:1] intValue]];
            [defaultsForAsk setObject:idToAsk forKey:@"IDTOASKVIEW"];


            flagToShowView = YES;
            listViewCntrl.getFlag = flagToShowView;
            [self viewDidLoadForDynamicFields];

        }
        else if([elements objectAtIndex:1] == [NSNull null])
        {
            [reader dismissViewControllerAnimated:YES completion:Nil];
            UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Invalid QR Code scanned" message:@"Please scan Collaborator's QR Code" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [message show];
        }
    }

    image.image =
    [info objectForKey: UIImagePickerControllerOriginalImage];

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

    [reader dismissViewControllerAnimated:YES completion:Nil];

}

1 个答案:

答案 0 :(得分:0)

您可以使用 - (void)viewWillAppear:(BOOL)ViewController类的动画方法重新显示视图。