2011-12-29 57 views
0

使用下面的代碼,但我沒有得到結果的文本框的值...任何幫助文本框的值的問題iPhone

-(IBAction) scanButtonTapped:(id)sender 
{ 
    int button = [sender tag]; 

    if (button == 1) { 
     NSLog(@"ID Button Pressed"); 
     deviceID.text = result; 
    } 
    else if (button == 2){ 
     NSLog(@"Key button Pressed"); 
     deviceKey.text = result; 
    } 

    NSLog(@"TBD: scan barcode here..."); 

    // ADD: present a barcode reader that scans from the camera feed 
    ZBarReaderViewController *reader = [ZBarReaderViewController new]; 
    reader.readerDelegate = self; 
    reader.supportedOrientationsMask = ZBarOrientationMaskAll; 

    ZBarImageScanner *scanner = reader.scanner; 
    // TODO: (optional) additional reader configuration here 

    // EXAMPLE: disable rarely used I2/5 to improve performance 
    [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0]; 

    // present and release the controller 
    [self presentModalViewController: reader animated: YES]; 

    [reader release]; 
} 

-(void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info 
{ 
    // ADD: get the decode results 

    id<NSFastEnumeration> results = 
    [info objectForKey: ZBarReaderControllerResults]; 
    ZBarSymbol *symbol = nil; 
    for(symbol in results) 
     // EXAMPLE: just grab the first barcode 
     break; 

    // EXAMPLE: do something useful with the barcode data 


    result = symbol.data; 

    NSLog(@"result = %@",result); 

    // EXAMPLE: do something useful with the barcode image 
    resultImage.image = 
    [info objectForKey: UIImagePickerControllerOriginalImage]; 

    // ADD: dismiss the controller (NB dismiss from the *reader*!) 
    [reader dismissModalViewControllerAnimated: YES];  
} 
+0

你剛纔談到的第一個函數'deviceID'和'deviceKey'文本字段? – 2011-12-29 06:10:33

+0

是的,我正在談論deviceID和deviceKey文本域 – AppDeveloper 2011-12-29 06:21:22

+0

你有適當的網點連接? 'NSLog'是否打印正確的值? – Ilanchezhian 2011-12-29 06:21:31

回答

0

,而不是按照行

result = symbol.data; 

使用以下

if(result) 
    [result release]; 

result = [symbol.data retain]; 
+0

獲取結果中的值,但未顯示在deviceID文本字段中,但在deviceKey中顯示值 – AppDeveloper 2011-12-29 06:29:44

+0

如果它將顯示在一個而不是另一箇中,看起來像插座連接問題。 – 2011-12-29 06:40:14

+0

檢查,它連接正確, – AppDeveloper 2011-12-29 06:49:03

0

假設result是正確的,等於symbol.data,你應該能夠設置使用文本:

[deviceID setText: result]; 

[deviceKey setText: result]; 

考慮symbol.data是一個NSString對象。如果無法正常工作,則Interface Builder中的插座沒有正確連接(deviceID和/或deviceKey插座)。