- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正面临这个无法解决的问题,很乐意得到你的帮助。
我有一个使用 ZBar 条形码扫描仪的 iPhone 应用程序。我有一个主视图 Controller ,它在按下 UIButton 时调用 ZBar 扫描仪。一旦扫描仪启动并检测到条形码编号,它就会自动关闭,我调用结果 View Controller 来显示一些扫描结果。我的问题是关闭结果 View Controller - 由于某种原因我不能关闭它并以干净的方式返回主视图 Controller 。我的解决方法是创建一个主视图 Controller 的新对象并调用它,这是一个非常糟糕的设计。
这是我的代码 - 感谢您的帮助!
在主视图 Controller 的某处调用扫描器(UIButton 操作方法):
ZBarReaderViewController *reader = [ZBarReaderViewController new];
UINavigationController *navCntrl1 = [[UINavigationController alloc] initWithRootViewController:reader];
reader.readerDelegate = self;
reader.title = @"Scan Barcode";
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner1 = reader.scanner;
[scanner1 setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
[scanner1 setSymbology: ZBAR_QRCODE config: ZBAR_CFG_ENABLE to: 0];
[self presentModalViewController:navCntrl1 animated:YES];
主 ViewController 中的 Scanner Delegate 方法:
//ZBarSDK Finish Scanning
- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
// EXAMPLE: do something useful with the barcode data
[self dismissModalViewControllerAnimated: YES];
//Calling the Results view controller
Results *resultsViewController = [[Results alloc] initWithNibName:nil bundle:nil];
resultsViewController.tempBarcode = barcode;
UINavigationController *resultsNavigationController = [[UINavigationController alloc] initWithRootViewController:resultsViewController];
resultsNavigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[[[UIApplication sharedApplication]delegate].window setRootViewController:resultsNavigationController];
}
这里说一下我尝试替换的地方:
[[[UIApplication sharedApplication]delegate].window setRootViewController:resultsNavigationController];
与:
[self presentModalViewController:resultsViewController animated:YES];
但如果我这样做,什么也不会发生。
在 Results ViewController 中,我这样做是为了返回到主视图 Controller :
ViewController *mainViewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
mainNavigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:mainNavigationController animated:YES];
而不仅仅是这个,这是行不通的:
[self dismissModalViewControllerAnimated:YES];
感谢您的耐心等待!
最佳答案
我有一个使用 ZBar 的类似应用程序。这是我对您的 UIButton 方法的模拟:
- (void)scanButtonTapped{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
// I need to scan only QR-codes
[scanner setSymbology:0 config:ZBAR_CFG_ENABLE to:0];
[scanner setSymbology:ZBAR_QRCODE config:ZBAR_CFG_ENABLE to:1];
reader.readerView.zoom = 1.0;
[self presentModalViewController:reader animated:YES];
[reader release];
}
这是我的 imagePickerController:didFinishPickingMediaWithInfo:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for (symbol in results)
break;
// Here I get the QR-code text
self.qrText = symbol.data;
NSLog(@"QR-code text = %@",self.qrText);
// Here I hide scanning View Controller from user
[picker dismissModalViewControllerAnimated:YES];
// Here I call QR-code text processing logic
[self ticketCheckOutLogic];
}
为了调用另一个 UIViewController,我建议在 [picker dismissModalViewControllerAnimated:YES] 之后发布通知;到您的 AppDelegate,例如:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:self.barcodeText, @"barcodeText", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"newBarcodeScanned" object:nil userInfo:options];
在 application:didFinishLaunchingWithOptions: 你可以这样写:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showResultView:)name:@"newBarcodeScanned" object:nil];
...你的 showResultView: 可以是这样的:
- (void)showResultView:(NSNotification *)notification {
//Calling the Results view controller
Results *resultsViewController = [[Results alloc] initWithNibName:@"ResultsView" bundle:nil];
NSDictionary *dict = [notification userInfo];
resultsViewController.tempBarcode = [dict objectForKey:@"barcodeText"];
[self presentModalViewController:resultsViewController animated:YES];
}
希望对您有所帮助:)
关于iphone - ZBarReaderViewController、 View Controller 层次结构和其他,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10290196/
我正在尝试将多个水平链接的 Button 和 TextView 垂直链接为 View 集,但仍保持平面 View 层次结构。这是我的初始布局和代码:
到目前为止,我已经在Google BigQuery上训练了几种模型,目前我需要查看模型的外观(即架构,损失函数等)。 有没有办法获取这些信息? 最佳答案 仔细阅读文档后,我可以说该功能尚不存在。我什至
本文实例讲述了PHP实现二叉树深度优先遍历(前序、中序、后序)和广度优先遍历(层次)。分享给大家供大家参考,具体如下: 前言: 深度优先遍历:对每一个可能的分支路径深入到不能再深入为止,而且每个
我是一名优秀的程序员,十分优秀!