Reputation: 135
I'm using the Zbar scanner SDK which lets me read barcodes. Now the default version stops scanning after one barcode is read and shows you the result. I've made my own UIToolBar with its own Done button because I want it to scan however many times, all of this shall be terminated whenever the user clicks on the "done" button on my UIToolBar. I've made the button, but how do I add the action to the button? It's quite confusing due to the pickerController's involvement and the Zbar SDK.How do I link the doneButton in my overlay to an action that terminates the scanning?
This is the overlay where I've set the Done button.
-(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;
This is the barcode scanner SDK's IPC section.
-(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];
}
Upvotes: 0
Views: 442
Reputation: 2987
Try to set action of dissmissmodalviewcontroller on doneButton using selector
[doneButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
In dismiss Method
-(void)dismiss
{
[self dismissmodalViewController];
}
Upvotes: 1