textfields值发行iPhone

时间:2011-12-29 06:05:33

标签: iphone objective-c ios

使用下面的代码,但我没有在textfields中得到结果的值...任何帮助

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

2 个答案:

答案 0 :(得分:0)

假设result正确且等于symbol.data,您应该可以使用以下方式设置文字:

[deviceID setText: result];

[deviceKey setText: result];

考虑symbol.data是一个NSString对象。如果这不起作用,则Interface Builder中的插座连接不正确(deviceID和/或deviceKey插座)。

答案 1 :(得分:0)

而不是跟随行

result = symbol.data;

使用以下

if( result )
  [result release];

result = [symbol.data retain];