Iphone 目标C使用ZBar扫描二维码后无法切换视图

Iphone 目标C使用ZBar扫描二维码后无法切换视图,iphone,objective-c,ios,xcode4.2,zbar-sdk,Iphone,Objective C,Ios,Xcode4.2,Zbar Sdk,我正在开发一个使用XCode 4.2检测二维码的应用程序 我试图在二维码检测后切换视图,但根本不起作用 以下是我使用的代码: - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

我正在开发一个使用XCode 4.2检测二维码的应用程序

我试图在二维码检测后切换视图,但根本不起作用

以下是我使用的代码:

- (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];
}
-(无效)imagePickerController:(UIImagePickerController*)读卡器
didFinishPickingMediaWithInfo:(NSDictionary*)信息
{
AudioServicesPlaySystemSound(kSystemSoundID_振动);
//添加:获取解码结果
id结果=
[信息对象forkey:ZBarReaderControllerResults];
ZBarSymbol*符号=nil;
用于(结果中的符号)
打破
NSString*string=symbol.data;
NSString*string2=@“1234”;
if([string IsequalString:string2]){
//这是不起作用的部分:它根本不加载AboutView
AboutView*about=[[AboutView alloc]initWithNibName:nil bundle:nil];
[self-presentModalViewController:关于动画:是];
}
否则{
UIAlertView*警报=[[UIAlertView alloc]initWithTitle:@“错误”
消息:@“这不是可识别的二维码!”
代表:赛尔夫
取消按钮:@“确定”
其他按钮:无];
[警报显示];
}
//添加:关闭控制器(注意从*读卡器*!)
[reader dismissModalViewControllerAnimated:是];
}

谢谢

问题在于,在zbar的示例代码中,读者就是视图控制器

-(void)presentReaderInViewController:(UIViewController*)vc
你对待自己就像它被呈现一样

您应该使用
reader
来显示您的
关于视图
,并且只在else块中关闭
reader

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];
        [reader 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];
    }
您可能还需要等待在警报视图的委托方法中关闭
阅读器
(创建一个软引用,并在设置警报视图时关闭该…myReader=reader;)

完全相同:关于你自己的问题。
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    [myReader dismissModalViewControllerAnimated: YES];

}