2011-12-07 74 views
0

我正在開發使用XCode 4.2的應用程序來檢測QR碼。objective C使用ZBar掃描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 *[email protected]"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]; 
} 

感謝

+0

完全重複:你自己的問題的http://stackoverflow.com/questions/8270275/presenting-view-modally-in-zbar-delegate-method。 – 0x8badf00d

回答

0

的問題是,閱讀器是zbar示例代碼中呈現的視圖控制器

-(void)presentReaderInViewController:(UIViewController*)vc 

,你就好像它被提交

您應該使用reader出示您的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;當您設置alertview)

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

} 
+0

它的工作原理! 非常感謝!!!!!!!!! – user1051935