私はこの解決できない問題に直面しており、喜んでお手伝いさせていただきます。
ZBar バーコード スキャナーを使用する iPhone アプリがあります。UIButton を押すと ZBar スキャナを呼び出すメイン ビュー コントローラがあります。スキャナーが起動し、バーコード番号が検出されると、それ自体を終了し、スキャンの結果を表示する結果ビュー コントローラーを呼び出します。私の問題は、結果のviewcontrollerを閉じることです-何らかの理由でそれを消すことができず、きれいな方法でメインのview 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 内から、これを実行してメインの View 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];
お待ちいただきありがとうございます。