gpt4 book ai didi

iOS:以编程方式调用的 segue 不起作用

转载 作者:行者123 更新时间:2023-11-29 12:20:18 25 4
gpt4 key购买 nike

我正在使用通过方法调用但未被触发的 SWRevealViewController segue。不会向日志报告任何错误,也不会导致应用程序挂起或崩溃。我已经检查了 Storyboard上的 segue 链接,它具有正确的类和标识符。

- (void)viewDidLoad {

[super viewDidLoad];

NSURL *url = [NSURL URLWithString:loadUrl];
NSLog(loadUrl);
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if([data length] > 0 && error == nil)
[mWebView loadRequest:request];
else if (error != nil)
NSLog(@"Error: %", error);}
];
}

- (void) captureOutput:(AVCaptureOutput *)captureOutput
didOutputMetadataObjects:(NSArray *)metadataObjects
fromConnection:(AVCaptureConnection *)connection
{
[metadataObjects
enumerateObjectsUsingBlock:^(AVMetadataObject *obj,
NSUInteger idx,
BOOL *stop)
{
if ([obj isKindOfClass:
[AVMetadataMachineReadableCodeObject class]])
{
// 3
AVMetadataMachineReadableCodeObject *code =
(AVMetadataMachineReadableCodeObject*)
[_previewLayer transformedMetadataObjectForMetadataObject:obj];
// 4
Barcode * barcode = [Barcode processMetadataObject:code];

for(NSString * str in self.allowedBarcodeTypes){
if([barcode.getBarcodeType isEqualToString:str]){
[self validBarcodeFound:barcode];
return;
}
}
}
}];
}


- (void) validBarcodeFound:(Barcode *)barcode{

[self stopRunning];
[self.foundBarcodes addObject:barcode];

NSString *input = [barcode getBarcodeData];
[NSString stringWithFormat:@"%lu",(unsigned long) [self.foundBarcodes count]-1];

if ([input length] >= 13)
{
input = [input substringToIndex:12];
}

loadUrl = [[@"http://www.mywebsite.com/" stringByAppendingString:input] stringByAppendingString:@"?utm_source=iphone"];
[super viewDidLoad];
[self performSegueWithIdentifier:@"toWebControl" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

[super viewDidLoad];
}

最佳答案

始终在主队列中执行转场。您的回调在单独的 NSOperationQueue 中执行,您需要将 performSegueWithIdentifier 包装在 dispatch_async(dispatch_get_main_queue,... 中。

此外,正如@rory-mckinnel 在评论中提到的那样,删除不必要的 [super viewDidLoad] 调用可能会导致意外结果。

关于iOS:以编程方式调用的 segue 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30849535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com