объектив C не может переключать виды после сканирования QR-кода с помощью ZBar - PullRequest
0 голосов
/ 07 декабря 2011

Я разрабатываю приложение, использующее XCode 4.2, который обнаруживает QR-код.

Я пытаюсь переключиться в режим просмотра после обнаружения 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];
}

спасибо

1 Ответ

0 голосов
/ 07 декабря 2011

Проблема в том, что читатель - это представленный контроллер представления в примере кода zbar

-(void)presentReaderInViewController:(UIViewController*)vc

, и вы рассматриваете себя так, как если бы он был представлен

Вы должны использовать readerпредставьте свой AboutView и только отклоните reader в блоке else

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];

}
...