squ*_*ime 9 iphone uialertview
我正在开发一个应用程序,当用户第一次开始使用UIAlert询问他们是否想要使用他们当前的位置时,会弹出UIAlert.这发生在主控制器内.但是,使用UIAlert时出现以下错误:
wait_fences: failed to receive reply: 10004003
Run Code Online (Sandbox Code Playgroud)
我调试了它,然后用Google搜索.我没有使用textarea或键盘输入,所以我不必辞职第一响应者.但是,我仍然无法弄清楚为什么我会收到此错误.它只在我添加UIAlert时出现.
MainController.m
- (void)viewDidLoad {
UIAlertView *mainAlert = [[UIAlertView alloc]
initWithTitle:@"Location"
message:@"Do you wish to use your current location?"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"No Thanks", @"Sure!", nil];
[mainAlert show];
[mainAlert release];
[super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud)
头文件的构造如下:
@interface MainController : UIViewController
<CLLocationManagerDelegate,
MKReverseGeocoderDelegate, UIAlertViewDelegate>
Run Code Online (Sandbox Code Playgroud)
Mac*_*ark 17
这样做的原因wait_fences: failed to receive reply:还可能是您尝试在不在其上时显示警报mainThread(这是GUI线程).
调度到GUI线程有助于:
dispatch_async(dispatch_get_main_queue(), ^{
[mainAlert show];
});
Run Code Online (Sandbox Code Playgroud)
我通过向UIAlert添加一点延迟解决了这个问题:下面是我的ViewDidLoad方法(它在ViewDidAppear中也可以正常工作):
[self performSelector:@selector(testAlert) withObject:nil afterDelay:0.1];
Run Code Online (Sandbox Code Playgroud)
由于某种原因,延迟成功了.然后我调用另一种方法(我当然会重命名它):
- (void) testAlert
{
UIAlertView *mainAlert = [[UIAlertView alloc] initWithTitle:@"Location" message:@"Do you wish to use your current location?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"No Thanks", @"Sure!", nil];
[mainAlert show];
[mainAlert release];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9322 次 |
| 最近记录: |