1

我想为 Scan Books 条形码创建应用程序,但是当我可以成功扫描条形码时,ZBarReaderViewController 不会在 imagePickerController didFinishPickingMediaWithInfo 委托中关闭,并且我收到警告:

警告:在演示或关闭过程中尝试从视图控制器中关闭!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    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
    resultLable.text = symbol.data;
    isbnResultString=symbol.data;
    NSLog(@"isbnResultString-----%@",isbnResultString);
    isbnLableText.text=isbnResultString;
    NSLog(@"%@",[info objectForKey: UIImagePickerControllerOriginalImage]);
    // EXAMPLE: do something useful with the barcode image
    barCodeImageView.image=[info objectForKey: UIImagePickerControllerOriginalImage];
    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [self dismissViewControllerAnimated:YES completion:nil];

    if (isbnResultString.length!=0)
    {
        if(![self connectedToInternet])
        {
            [appDelagate showActivityIndicator];
            appDelagate.isNetConnected=NO;
            [self internetAlert];
        }
        else
        {
            [self getBookDetailsByISBN:symbol.data];
        }
    }
}

如何关闭 ZBarReaderViewController?

4

1 回答 1

1

有同样的问题, performSeletor:withObject:afterDelay: 对我来说很好。

- (void)imagePickerController:(UIImagePickerController *)reader didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // do some userful stuff

    [self performSelector:@selector(dismissZBar) withObject:nil afterDelay:1];
}

- (void)dismissZBar {
    [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
        // do some stuff after dismiss
    }];
}
于 2013-11-30T22:43:42.680 回答