Я работаю над приложением iOS. Я пытаюсь отобразить обнаруженную строку из AVFoundation, «BarcodeNum». Но он отображается неправильно. Ниже мой кодObjective-C: отображение значения из другого класса
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
@property (strong, nonatomic) NSString *detectionString;
@property (strong, nonatomic) NSString *barcodeNum;
@end
FirstViewController.m
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
CGRect highlightViewRect = CGRectZero;
AVMetadataMachineReadableCodeObject *barCodeObject;
self.detectionString = nil;
NSArray *barCodeTypes = @[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code,
AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code,
AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode];
for (AVMetadataObject *metadata in metadataObjects) {
for (NSString *type in barCodeTypes) {
if ([metadata.type isEqualToString:type])
{
barCodeObject = (AVMetadataMachineReadableCodeObject *)[_prevLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata];
highlightViewRect = barCodeObject.bounds;
self.detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Barcode Detected" message:self.detectionString preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yes = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
FirstViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"new"];
[self presentViewController:vc animated:YES completion:nil];
}];
UIAlertAction* no = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
[alert addAction:yes];
[alert addAction:no];
[self presentViewController:alert animated:YES completion:nil];
break;
}
}
if (self.detectionString != nil)
{
_label.text = self.detectionString;
self.barcodeNum = self.detectionString;
break;
}
else
_label.text = @"Barcode not found";
}
_highlightView.frame = highlightViewRect;
}
SecondView.m
#import "SecondView.h"
#import "FirstViewController.h"
#import <Foundation/Foundation.h>
@interface SecondView()
@property (strong, nonatomic) IBOutlet UILabel *label;
@end
@implementation SecondView
- (void)viewDidLoad
{
[super viewDidLoad];
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
_label.text=[NSString stringWithFormat:@"%@",firstViewController.barcodeNum];
//Not displaying the barcode number detected
}
@end
вы переходите в FirstViewController, а затем почему вы проверяете значение штрих-кода в secondView? Как вы переходите на второй взгляд? –
вам нужно объявить свойства в файле .h, если вы хотите получить к ним доступ из других классов. –
@ Mr.T Я перемещаюсь по модальному в кнопке AlertController. Я хочу представить значение, обнаруженное в FirstView, в метку в SecondView. Я объявлял barcodeNum в файле FirstView «h». Я не размещал код ни для чего –