Ios NSoperation-块外不可见字符串
我目前正在从事一个项目,并使用tesseract API 代码如下:Ios NSoperation-块外不可见字符串,ios,objective-c,nsoperation,Ios,Objective C,Nsoperation,我目前正在从事一个项目,并使用tesseract API 代码如下: UIImage *bwImage = [image g8_blackAndWhite]; [self.activityIndicator startAnimating]; // Display the preprocessed image to be recognized in the view self.imageView.image = bwImage; G8RecognitionOperation *operatio
UIImage *bwImage = [image g8_blackAndWhite];
[self.activityIndicator startAnimating];
// Display the preprocessed image to be recognized in the view
self.imageView.image = bwImage;
G8RecognitionOperation *operation = [[G8RecognitionOperation alloc] init];
operation.tesseract.engineMode = G8OCREngineModeTesseractOnly;
operation.tesseract.pageSegmentationMode = G8PageSegmentationModeAutoOnly;
operation.delegate = self;
operation.recognitionCompleteBlock = ^(G8Tesseract *tesseract) {
// Fetch the recognized text
NSString *recognizedText = tesseract.recognizedText;
NSLog(@"%@", recognizedText);
[self.activityIndicator stopAnimating];
// Spawn an alert with the recognized text
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"OCR Result"
message:recognizedText
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
};
//NSLog(@"%@",);
// Finally, add the recognition operation to the queue
[self.operationQueue addOperation:operation];
}
我想将识别的文本字符串传递给第二视图控制器,但它在块外不可见
我怎样才能做到这一点,有什么建议吗 使用
\u block
关键字声明recognizedText
外部块,使其在块外部可见
如下代码所示:
......
__block NSString *recognizedText;//declared outside to make it visible outside block
operation.recognitionCompleteBlock = ^(G8Tesseract *tesseract) {
// Fetch the recognized text
recognizedText = tesseract.recognizedText;
NSLog(@"%@", recognizedText);
[self.activityIndicator stopAnimating];
// Spawn an alert with the recognized text
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"OCR Result"
message:recognizedText
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
};
......
第二个视图控制器是什么?我想让这个字符串在块外可见,并传递可以加载到另一个视图控制器Rok中的数据,是什么阻止了你做你想做的事?在块外声明
recognizedText
变量。在块外声明变量,并在声明前加上u块关键字。谢谢你的回复。我在块外声明了它,但当我试图打印它时,没有显示任何内容NSLog(@“%@”,recognizedText);基本上,我试图实现的是,消息显示为警报,但我想传递字符串并使用Segue在另一个视图控制器上显示。完全执行块后,您将获得结果。这意味着您想在警报消息弹出时重定向下一页?altert message pop重定向到新页,但我想传递此消息字符串:识别下一页文本视图中的文本,以便对其进行编辑。。。。