NSoperation - 字符串在块外不可见

时间:2016-10-26 04:43:25

标签: 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 *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];

}

我想将 recognText string 传递给第二个View控制器,但在块外不可见。

我如何实现这一点,任何建议?

1 个答案:

答案 0 :(得分:0)

使用recognizedText关键字在{}}块外部声明,以使其在块外可见。

如下面的代码:

__block