很多时候,我们需要用到多线程的东西,比如红外线检测是否有人经过。这种情况需要搞个子线程在后台不断的检测,这个线程可能是第三方提供的,你调用它给的方法,然后显示提示框的时候,问题就来了。

  提示信息:This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.

  复杂、耗时的操作需要放在子线程,这样不会堵塞主线程的操作。但是,与UI相关的操作,必须回到主线程中执行。

  方法如下:

dispatch_async(dispatch_get_main_queue(), ^{

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"侦测到门前有人!" message:nil delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];

        [alertView show];

    });

相关文章:

  • 2021-05-30
  • 2021-07-11
  • 2021-11-05
  • 2021-05-29
  • 2021-12-13
  • 2022-12-23
  • 2021-08-15
猜你喜欢
  • 2021-11-01
  • 2021-07-05
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案