代码之家  ›  专栏  ›  技术社区  ›  squeezemylime

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

  •  9
  • squeezemylime  · 技术社区  · 14 年前

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

    wait_fences: failed to receive reply: 10004003
    

    我调试了它,然后到处搜索。我没有使用文本区域或键盘输入,所以我不必辞去第一响应者的职务。然而,我仍然不明白为什么我会得到这个错误。它只在我添加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>
    
    5 回复  |  直到 13 年前
        1
  •  17
  •   Atulkumar V. Jain    12 年前

    原因是 wait_fences: failed to receive reply: 也可能是您试图在不在 mainThread (这是GUI线程)。

    分派到GUI线程有助于:

    dispatch_async(dispatch_get_main_queue(), ^{ 
      [mainAlert show];
    });
    
        2
  •  8
  •   Atulkumar V. Jain    12 年前

    我通过在UIAlert中添加一点延迟来解决这个问题:下面是 视图加载 方法(在 视图显示 ):

    [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];
    }
    
        3
  •  1
  •   Atulkumar V. Jain    12 年前

    总是打电话 [super viewDidLoad]; 在你做其他事情之前。这也解释了为什么拖延有效。

    希望我是对的。:)

        4
  •  0
  •   Alan Rogers    14 年前

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

        5
  •  0
  •   Joe M    11 年前

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

    因此,ViewController试图在完全绘制自己的视图之前显示一个UIAlertView。

    我将观察者添加到ViewDidAppear,并在ViewDidAppear中启动了可达性的startNotifier。代码中也错过了对[super viewdideappear]的调用。这两个问题都解决了,应用程序又恢复了正常工作。

    如果您收到此wait-fences:failed to receive reply:10004003 error once,则可能无法在应用程序中进一步显示任何模式视图控制器。这就是我在应用程序中遇到的问题。有时,当试图呈现一个模式ViewController时,应用程序将进入无限循环。

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