Iphone ZBarReaderViewController、视图控制器层次结构和其他
我面临着这个无法解决的问题,很高兴能得到你的帮助 我有一个使用ZBar条形码扫描仪的iphone应用程序。我有一个主视图控制器,只要按下一个按钮就可以调用ZBar扫描仪。一旦扫描仪启动并检测到条形码编号,它就会自动关闭,我会调用结果视图控制器,它会显示一些扫描结果。我的问题是忽略结果视图控制器-出于某种原因,我无法缩小它并以干净的方式返回主视图控制器。我的工作是创建一个主视图控制器的新对象并调用它,这是一个非常糟糕的设计 这是我的代码-感谢任何帮助 在主Viewcontroller中的某个位置调用扫描仪(UIButton操作方法): 主ViewController中的扫描仪委派方法:Iphone ZBarReaderViewController、视图控制器层次结构和其他,iphone,objective-c,ios,uiviewcontroller,barcode-scanner,Iphone,Objective C,Ios,Uiviewcontroller,Barcode Scanner,我面临着这个无法解决的问题,很高兴能得到你的帮助 我有一个使用ZBar条形码扫描仪的iphone应用程序。我有一个主视图控制器,只要按下一个按钮就可以调用ZBar扫描仪。一旦扫描仪启动并检测到条形码编号,它就会自动关闭,我会调用结果视图控制器,它会显示一些扫描结果。我的问题是忽略结果视图控制器-出于某种原因,我无法缩小它并以干净的方式返回主视图控制器。我的工作是创建一个主视图控制器的新对象并调用它,这是一个非常糟糕的设计 这是我的代码-感谢任何帮助 在主Viewcontroller中的某个位置调
//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];
}
ViewController *mainViewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
mainNavigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:mainNavigationController animated:YES];
与:
但如果我这样做,什么也不会发生
在结果视图控制器中,我执行此操作以返回主视图控制器:
//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];
}
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方法的模拟:
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];
- (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];
}
在应用程序中:didFinishLaunchingWithOptions:您可以编写如下内容:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showResultView:)name:@"newBarcodeScanned" object:nil];
- (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];
}
。。。您的showResultView:可以是这样:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showResultView:)name:@"newBarcodeScanned" object:nil];
- (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];
}
希望有帮助:)我有一个使用ZBar的类似应用程序。以下是我对您的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];
- (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];
}
在应用程序中:didFinishLaunchingWithOptions:您可以编写如下内容:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showResultView:)name:@"newBarcodeScanned" object:nil];
- (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];
}
。。。您的showResultView:可以是这样:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showResultView:)name:@"newBarcodeScanned" object:nil];
- (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];
}
希望对您有所帮助:)my delegate method-(void)imagePickerController:(UIImagePickerController*)picker未完成PickingMediaWithInfo:(NSDictionary*)信息未被调用。有任何帮助吗?我的委托方法-(void)imagePickerController:(UIImagePickerController*)picker未完成PickingMediaWithInfo:(NSDictionary*)信息未被调用。有什么帮助吗?