Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Only run on the main thread!’
swift sizeThatFits Only run on the main thread
“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.
"
->确保调用此函数时候,是处于界面的主线程。
从:
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