无法解雇imagePickerController中的ZBarReaderViewController didFinishPickingMediaWithInfo

时间:2013-04-05 15:44:48

标签: controller warnings barcode dismiss zbar

您好我正在开发一个QR码阅读器应用程序,在解雇ZBarReaderViewController时遇到了很多麻烦。我有一个带有按钮的视图控制器,可以创建阅读器并显示它。

- (IBAction)scanAction:(id)sender {

    ZBarReaderViewController *reader = [ZBarReaderViewController new];


    reader.readerDelegate = self;
    [reader.scanner setSymbology: ZBAR_I25
                               config: ZBAR_CFG_ENABLE
                                   to: 0];
    reader.readerView.zoom = 1.0;

//    [self presentViewController:reader animated:YES completion:nil];
    [self presentModalViewController:reader animated:YES];
}

然后在读者的代表我这样做(我评论了结果处理行,但我仍然得到相同的错误):

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
//    id<NSFastEnumeration> results =  [info objectForKey: ZBarReaderControllerResults];
//    
//    ZBarSymbol *symbol = nil;
//    NSURL *url;
//    NSString * textUrl;
//    
//    for(symbol in results){
//        textUrl = symbol.data;
//        NSLog(@"%@",textUrl);
//        url = [NSURL URLWithString:textUrl];
//        break;
//    }
//    
//    if (url != nil) {
////        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
////        [self.webView loadRequest:requestObj];
//        [self.urlLabel setText:textUrl];
//    }

//    [reader dismissViewControllerAnimated:NO completion:nil];
    [reader dismissModalViewControllerAnimated:YES];
}

这是我随机出现的错误:

QR reader[10159:907] Warning: Attempt to dismiss from view controller <ViewController: 0x1ed4c930> while a presentation or dismiss is in progress!

有时它会在没有任何警告的情况下进行扫描和解散,但是当我收到警告时,读者会继续扫描,并且再次调用代理,直到不再显示警告为止。

我尝试了其他用户遇到同样问题的建议,但在我的特定情况下无效:

  1. 使用dismissModalViewController而不是不推荐使用的模态视图。
  2. 在dismissViewControllerAnimated方法的完成块中附加结果处理。
  3. 感谢阅读:)

1 个答案:

答案 0 :(得分: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
      }];
}