最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

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

Swift crifan 191浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
18 queries in 0.226 seconds, using 9.89MB memory