UIAlertView:wait_fences:无法收到答复:10004003 [英] UIAlertView: wait_fences: failed to receive reply: 10004003

查看:64
本文介绍了UIAlertView:wait_fences:无法收到答复:10004003的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在后台运行一个Web请求,我希望用户能够取消此请求.当Web请求运行时,我将UIActionSheet与Cancel按钮一起使用.当Web请求返回错误时,我通过调用DismissWithClickedButtonIndex(0,true)关闭UIActionSheet.然后,我显示一个带有错误消息的UIAlertView以及取消或重试Web请求的选项.

I'm running a web request in the background and I want the user to be able to cancel this request. I use a UIActionSheet with a Cancel button while the web request is running. When the web request returns an error, I close the UIActionSheet by calling DismissWithClickedButtonIndex(0, true). Then I show a UIAlertView with an error message and the option to cancel or retry the web request.

大多数情况下,一切正常,但是有时我在控制台输出窗口中收到"wait_fences:未能收到回复:10004003"消息,并且偶然地有些奇怪的UI行为.

Everything works fine most of the time, but sometimes I get the "wait_fences: failed to receive reply: 10004003" message in the console output window and incidentally there is some strange UI-behaviour.

我进行了一些搜索,发现这是由诸如底层视图无法在将控件转移到UIAlertView之前获取控件之类的原因引起的.有人建议通过使用PerformSelector延迟显示AlertView.这是正确的解决方案吗?如果是这样,如何将UIAlertView的Show方法转移到PerformSelector方法的第一个参数?

I did some searching and found out that this is caused by something like the underlaying view cannot get control before the control is transferred to the UIAlertView. Some people suggested to delay showing the AlertView by using PerformSelector. Is this the right solution? If so, how do I transfer the Show method of the UIAlertView to the first parameter of the PerformSelector method?

当前,我将这种解决方案用于延迟:

Currently I use this solution for the delay:

private void StartAfterParentViewUpdate(NSAction action)
{
    NSAction delayedAction = () => BeginInvokeOnMainThread(action);
    NSTimer.CreateScheduledTimer(new TimeSpan(0, 0, 0, 0, 200), delayedAction);
}

这样,我可以调用StartAfterParentViewUpdate(_alertView.Show),并且我猜只要线程可以处理它,它将在主UI线程上运行.这是正确的还是有更好的方法来解决此问题?

This way I can call StartAfterParentViewUpdate(_alertView.Show) and I guess it will run on the main UI thread as soon as the thread can handle it. Is this correct or is there a better way to solve this problem?

推荐答案

要回答我自己的问题:解决方案很好,我再也没有看到wait_fences消息.我做了一个静态助手,可以在任何类中使用:

To answer my own question: the solution works good, I never saw the wait_fences message again. I made a static helper to use from any class:

public static class UIHelper
{
    public static void StartAfterParentViewUpdate(NSObject parent, NSAction action)
    {
        NSTimer.CreateScheduledTimer(new TimeSpan(0, 0, 0, 0, 100), () => parent.BeginInvokeOnMainThread(action));
    }

    // Use this helper method only when action is a non-static member of an object.
    public static void StartAfterParentViewUpdate(NSAction action)
    {
        StartAfterParentViewUpdate((NSObject)action.Target, action);
    }
}

如果需要延迟对带有参数的方法的调用,请使用匿名委托.示例:

If you need to delay the call to a method with parameters, use an anonymous delegate. Example:

    NSAction action = () => { viewController.NavigationController.PopViewControllerAnimated(true); };
    UIHelper.StartAfterParentViewUpdate(viewController, action);

这篇关于UIAlertView:wait_fences:无法收到答复:10004003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆