我正面臨着這個無法解決的問題,並很樂意爲您提供幫助。ZBarReaderViewController,視圖控制器層次結構和其他
我有一個使用ZBar條碼掃描器的iPhone應用程序。我有一個主視圖控制器,通過按下UIButton來調用ZBar掃描儀。一旦掃描儀啓動並檢測到條形碼號碼,它就會自行關閉,我打電話給顯示掃描結果的結果視圖控制器。我的問題是關閉結果viewcontroller - 從某種原因,我不能淡化它,並以乾淨的方式回到主視圖控制器。我的工作是創建主視圖控制器的一個新對象並稱之爲,這是一個非常糟糕的設計。
這是我的代碼 - 感謝任何幫助!
在主視圖控制器(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];
主視圖控制器中的掃描儀的委託方法:
//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];
With:
[self presentModalViewController:resultsViewController animated:YES];
但是,如果我這樣做沒有任何反應。
從視圖控制器我這樣做是爲了回到主視圖控制器在結果中:
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];
感謝您的耐心!
我的委託方法 - (void)imagePickerController:(UIImagePickerController *)picker didFinish PickingMediaWithInfo:(NSDictionary *)info沒有被調用。任何幫助? – Nil 2012-12-29 04:50:16