2012-07-23 66 views
0

我正在使用Zbar掃描儀SDK,它可以讓我讀取條形碼。現在,默認版本在讀取一個條形碼後停止掃描並顯示結果。我用自己的Done按鈕創建了自己的UIToolBar,因爲我希望它多次掃描,只要用戶點擊我的UIToolBar上的「完成」按鈕,所有這些都將被終止。我已經制作了按鈕,但是如何將操作添加到按鈕?由於pickerController的參與和Zbar SDK,這是相當混亂的。我如何將覆蓋層中的doneButton鏈接到終止掃描的操作?如何使用自定義按鈕消除UImagePickerController的視圖?

這是我已經設置完成按鈕的覆蓋。

-(UIView*)CommomOverlay { 

UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 428, 320, 70)]; 
[myToolBar setBarStyle:UIBarStyleBlackTranslucent]; 

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonTap:)]; 

[myToolBar setItems:[NSArray arrayWithObjects:doneButton, nil] animated:YES]; 
[FrameImg addSubview:myToolBar]; 
[view addSubview:FrameImg]; 
return view; 

這是條碼掃描器SDK的IPC部分。

-(void) imagePickerController: (UIImagePickerController*) 
readerdidFinishPickingMediaWithInfo: (NSDictionary*) info { 
{ 

// ADD: get the decode results 
id<NSFastEnumeration> results = 
[info objectForKey: ZBarReaderControllerResults]; 
ZBarSymbol *symbol = nil; 
for(symbol in results) 
// EXAMPLE: just grab the first barcode 
break; 
// EXAMPLE: do something useful with the barcode data 
resultText.text = symbol.data; 

// setup our custom overlay view for the camera 
// ensure that our custom view's frame fits within the parent frame 
// EXAMPLE: do something useful with the barcode image 
resultImage.image = 
[info objectForKey: UIImagePickerControllerOriginalImage]; 

// ADD: dismiss the controller (NB dismiss from the *reader*!) 
//Delete below in entirety for continuous scanning. 
[reader dismissModalViewControllerAnimated: NO]; 
} 
+0

您是否嘗試過使用選擇 – 2012-07-23 05:34:39

+0

讓我知道設置dissmissmodalviewcontroller的動作上完成的按鈕如果它工作 – 2012-07-23 05:36:53

+0

您在下面的評論中發佈了該應用程序崩潰,請張貼崩潰日誌,以便我們可以更好地瞭解發生了什麼問題。 – 2012-07-23 12:02:59

回答

1

嘗試使用選擇

上設置doneButton dissmissmodalviewcontroller的行動
[doneButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 

在解僱法

-(void)dismiss 
    { 

    [self dismissmodalViewController]; 

    } 
+0

感謝您的幫助,但它不起作用。我在覆蓋區域中實現了第一行代碼。該應用程序實際上在啓動時崩潰。讓我們忘記規範,我將如何通過使用done按鈕來終止UIImagePickerController會話? – 2012-07-23 06:28:15

+0

你在doneButtonTap方法中寫了些什麼 – 2012-07-23 06:40:08