Getting a “This application is modifying the autolayout engine from a background thread” error?

后端 未结 21 1938
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 15:52

Been encountering this error a lot in my OS X using swift:

\"This application is modifying the autolayout engine from a background thread, which can

21条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 16:21

    Obviously you are doing some UI update on back ground thread. Cant predict exactly where, without seeing your code.

    These are some situations it might happen:-

    you might be doing something on background thread and not using. Being in the same function this code is easier to spot.

    DispatchQueue.main.async { // do UI update here }
    

    calling a func doing web request call on background thread and its completion handler calling other func doing ui update. to solve this try checking code where you have updated the UI after webrequest call.

    // Do something on background thread
    DispatchQueue.global(qos: .userInitiated).async {
       // update UI on main thread
       DispatchQueue.main.async {
                    // Updating whole table view
                    self.myTableview.reloadData()
                }
    }
    

提交回复
热议问题