Objective C 使用 ZBar 扫描二维码后无法切换视图
我正在使用 XCode 4.2 开发一个检测 QR 码的应用程序。
我试图在二维码检测后切换视图,但它根本不起作用,
这里是正在使用的代码:
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
NSString *string=symbol.data;
NSString *string2=@"1234";
if ([string isEqualToString:string2]) {
//this is the part that is not working : it doesn t load the AboutView at all
AboutView *about = [[AboutView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:about animated:YES];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"This is not a recognized QR code!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
谢谢
I am developping an App using XCode 4.2 that detects a QR code.
I am trying to make a switch view after QR code detection but it is not working at all
here is the code am using :
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
NSString *string=symbol.data;
NSString *string2=@"1234";
if ([string isEqualToString:string2]) {
//this is the part that is not working : it doesn t load the AboutView at all
AboutView *about = [[AboutView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:about animated:YES];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"This is not a recognized QR code!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 reader 是 zbar 示例代码中呈现的视图控制器
,并且您将 self 视为呈现的
您应该使用
reader
来呈现您的AboutView
并仅关闭else 块中的reader
您可能还想等待在警报视图的委托方法中关闭
reader
(创建一个软引用并关闭该... myReader = reader ; 当您设置警报视图时)The issue is that the reader is the presented view controller in zbar's example code
and you are treating self as if it is presented
You should use
reader
to present yourAboutView
and only dismissreader
in the else blockYou might also want to wait to dismiss
reader
in the delegate method of your alert view (create a soft reference and dismiss that... myReader = reader; when you set up the alertview)