wait_fences:无法接收回复:10004003 错误 - UIAlert 不存在 UITextField

发布于 2024-10-03 07:43:14 字数 914 浏览 0 评论 0原文

我正在开发一个应用程序,当用户第一次开始使用它时,会弹出 UIAlert 来询问他们是否想要使用当前位置。这发生在主控制器内。但是,在使用 UIAlert 时出现以下错误:

wait_fences: failed to receive reply: 10004003

我对其进行了调试,并用 google 进行了搜索。我没有使用文本区域或键盘输入,因此我不必辞去第一响应者的职务。但是,我仍然无法弄清楚为什么会收到此错误。它仅在我添加 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];
}

头文件的构造如下:

@interface MainController : UIViewController 
<CLLocationManagerDelegate,
 MKReverseGeocoderDelegate, UIAlertViewDelegate>

I am working on an app where a UIAlert pops up the first time the user begins using it to ask if they want to use their current location. This happens within the main controller. However, I get the following error when using the UIAlert:

wait_fences: failed to receive reply: 10004003

I debugged it, and googled around. I am not using a textarea or keyboard input, so I don't have to resign a first responder. However, I still cannot figure out why I would be getting this error. It only appears when I add the 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];
}

The header file is constructed like this:

@interface MainController : UIViewController 
<CLLocationManagerDelegate,
 MKReverseGeocoderDelegate, UIAlertViewDelegate>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

初见 2024-10-10 07:43:14

wait_fences: failed to receive returned: 的原因也可能是您尝试在不在 mainThread(即 GUI 线程)上时显示警报。

分派到 GUI 线程有助于:

dispatch_async(dispatch_get_main_queue(), ^{ 
  [mainAlert show];
});

The reason for this wait_fences: failed to receive reply: can also be that you try to show an alert while not being on the mainThread (which is the GUI thread).

Dispatching to the GUI thread helps:

dispatch_async(dispatch_get_main_queue(), ^{ 
  [mainAlert show];
});
独﹏钓一江月 2024-10-10 07:43:14

我通过向 UIAlert 添加轻微的延迟解决了这个问题:下面是我的 ViewDidLoad 方法中的内容(它在 ViewDidAppear 中也可以正常工作):

[self performSelector:@selector(testAlert) withObject:nil afterDelay:0.1];

由于某种原因,延迟确实诡计。然后我调用了另一个方法(当然我会重命名它..):

- (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];
}

I solved this problem by adding a slight delay to the UIAlert: The below is within my ViewDidLoad method (it also works fine within ViewDidAppear):

[self performSelector:@selector(testAlert) withObject:nil afterDelay:0.1];

for some reason that delay did the trick. I then called another method (I will rename it of course..):

- (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];
}
ι不睡觉的鱼゛ 2024-10-10 07:43:14

在执行任何其他操作之前,请始终调用 [super viewDidLoad];。这也解释了为什么延迟会起作用。

希望我是对的。 :)

Always call [super viewDidLoad]; before you do anything else. That is also explaining why the delay works.

Hope I'm right. :)

断念 2024-10-10 07:43:14

尝试在 -viewDidAppear:(BOOL)animated 中显示 UIAlert。 -viewDidLoad 在视图加载时但在屏幕上显示之前调用。

Try showing the UIAlert in -viewDidAppear:(BOOL)animated. -viewDidLoad is called when your view is loaded, but before it is on screen.

浅忆 2024-10-10 07:43:14

我有类似的问题。我在 ViewDidLoad 中添加了一个观察者以获取可达性通知,该通知是在 ViewDidAppear 完成之前发布的。

所以 ViewController 试图在自己的 View 完全绘制之前显示一个 UIAlertView。

我将观察者的添加移至 ViewDidAppear,并在 ViewDidAppear 中启动可达性的 startNotifier。代码中还遗漏了对 [super viewDidAppear] 的调用。这两个问题都得到纠正,应用程序再次正常运行。

如果您收到此 wait_fences: failed to receive reply: 10004003 错误一次,您可能无法进一步在应用程序中呈现任何模式 ViewController。这是我在我的应用程序中遇到的问题。有时,当尝试呈现一个模式 ViewController 时,应用程序会进入无限循环。

正如艾伦所说,永远记住“尝试在 -viewDidAppear:(BOOL)animated 中显示 UIAlert。-viewDidLoad 在视图加载时但在屏幕上显示之前调用。”

I had a similar problem. I was adding an observer in the ViewDidLoad for a reachability notification, which was getting posted before the ViewDidAppear was finished.

So the ViewController was trying to display one UIAlertView before its own View was drawn completely.

I moved the adding of Observers to the ViewDidAppear, and started the startNotifier of reachability in the ViewDidAppear. Also the call to [super viewDidAppear] was missed from the code. Both these issues corrected, the app became working fine again.

If you get this wait_fences: failed to receive reply: 10004003 error once, you may not be able to present any modal ViewControllers in the app further. This was the problem I had in my app. Sometimes when trying to present one modal ViewController, the app would go into an infinite loop.

As Alan said, always remember to "Try showing the UIAlert in -viewDidAppear:(BOOL)animated. -viewDidLoad is called when your view is loaded, but before it is on screen."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文