最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift的UITextView的sizeThatFits出错:Terminating app due to uncaught exception NSInternalInconsistencyException reason Only run on the main thread

Swift crifan 2704浏览 0评论

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Only run on the main thread!’

swift sizeThatFits Only run on the main thread

UIView Class Reference

“Threading Considerations

Manipulations to your application’s user interface must occur on the main thread. Thus, you should always call the methods of the UIView class from code running in the main thread of your application. The only time this may not be strictly necessary is when creating the view object itself but all other manipulations should occur on the main thread.

"

->确保调用此函数时候,是处于界面的主线程。

ios – ‘NSInternalInconsistencyException’, reason: ‘Only run on the main thread!’ error – Stack Overflow

从:

msgTVC.messageTableView.reloadData()
        //do scroll
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            //
         }

改为:

        //do scroll
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            //reload table data
            //Note: must call reloadData in main ui thread
            //-> later will call calcTexViewTextSize->sizeThatFits
            //-> method sizeThatFits required in main UI thread
            msgTVC.messageTableView.reloadData()
         }

即可。

->即,保证了tableView的reloadData是在主界面的线程中。

转载请注明:在路上 » [已解决]swift的UITextView的sizeThatFits出错:Terminating app due to uncaught exception NSInternalInconsistencyException reason Only run on the main thread

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.179 seconds, using 22.09MB memory