iOS开发——modifying the autolayout engine from a background thread

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

  提示信息: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];

    });

原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/5337167.html