0

我正在使用检测 QR 码的 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];
}

谢谢

4

1 回答 1

0

问题是阅读器是 zbar 示例代码中呈现的视图控制器

-(void)presentReaderInViewController:(UIViewController*)vc

你对待自己就像它被呈现一样

你应该使用reader来展示你的并且只在 else 块中AboutView关闭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];
    }

您可能还想reader在警报视图的委托方法中等待解除(创建软引用并解除... myReader = reader; 当您设置警报视图时)

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    [myReader dismissModalViewControllerAnimated: YES];

}
于 2011-12-07T17:10:08.803 回答