gpt4 book ai didi

ios - 通过变量使 UIAlertView 触发

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

一些二维码扫描器应用程序会在完成扫描后通过警报显示结果(URL 或其他东西),所以我想做同样的事情并通过警报显示我的视频处理结果(整数)。我的视频处理函数是一个委托(delegate)方法。我阅读了一些 UIAlertView 示例,但需要按钮来触发警报。在我的例子中,需要在计算变量 result 后显示警报。但是,如果我在 processImage 函数中添加警报:

- (void)processImage:(cv::Mat&)image {
int result;
videoProcessing() {
...
result = 10
}

if (result == 10) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"The code is" message:@"10"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}

我的应用程序将因错误而终止:

2014-04-17 11:11:02.189 DotReader[3813:1803] *** Assertion failure in -[UIKeyboardTaskQueue performTask:], /SourceCache/UIKit/UIKit-2935.137/Keyboard/UIKeyboardTaskQueue.m:388
2014-04-17 11:11:02.190 DotReader[3813:1803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue performTask:] may only be called from the main thread.'
*** First throw call stack:
(0x183ab6950 0x18ffbc1fc 0x183ab6810 0x1845eedb4 0x186aa8fc0 0x186aa8eec 0x186aa8b50 0x186aa6588 0x186aa565c 0x186f811d0 0x186f81698 0x186b00c7c 0x186affa04 0x186f83010 0x10007ad0c 0x10013c374 0x1827b8434 0x190594014 0x190593fd4 0x19059a4a8 0x1905964c0 0x19059b0f4 0x19059b4fc 0x1907296bc 0x19072954c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

谁能告诉我如何正确添加UIAlertView

最佳答案

所有的 UI 事件都应该从主线程调用

if (result == 10) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"The code is" message:@"10"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
});

}

关于ios - 通过变量使 UIAlertView 触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23124136/

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