iPhone从单一方法获得两个不同文本域的价值

时间:2011-12-27 16:18:42

标签: iphone objective-c ios

使用下面的代码,问题是我有两个按钮和两个文本字段,但我使用单一方法获取qrcode值。我如何将它用于两个文本域

- (IBAction) keyScanButtonTapped
{

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

deviceKey.text = symbol.data;

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

1 个答案:

答案 0 :(得分:0)

您是否只想将两个不同的按钮连接到同一个功能?这是没问题的,只需进入界面构建器并将两个按钮连接到此方法即可。您可以在界面构建器

中看到有关如何连接按钮的问题

How can I connect "File's Owner" with a button in a Toolbar?

当调用回调函数时,您可以以这种方式识别称为函数的按钮

-(void)buttonPressed:(id)sender{
    //find out which button was pressed
    UIButton * pressed = (UIButton*) sender;
    NSInteger tag = pressed.tag;
}

标签在界面构建器中定义,只需确保两个按钮的标签不同,您就可以了。