2

Prior to iOS 11 I was able to reload a table views data on the fly without having to dispatch the reload to the main thread. However, now that I am testing on a device that has iOS 11 installed it seems I have to dispatch every UI update to the main thread in order for it to work. Or else I end up with empty UI elements. i.e. table views with all the rows but no labels, or buttons with no titles, etc.

Does anyone know what changed in iOS 11 to require this? Is there a way to turn it off?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
tentmaking
  • 2,076
  • 4
  • 30
  • 53
  • Microsoft did this long time ago with C# – Yitzchak Nov 30 '17 at 21:36
  • For good measure: [the docs](https://developer.apple.com/documentation/uikit) just a little way down. Search for “important” – allenh Nov 30 '17 at 21:46
  • FYI - reloading the table view from the background prior to iOS 11 was never the proper thing to do. Didn't you notice that it didn't work very well (long delays in reloading, for example)? – rmaddy Dec 01 '17 at 00:02
  • Actually, it worked fine. There weren't any delays or random one-off quirks at all. That's why I'm so confused. I feel like I've missed a huge part of iOS Development, but I never noticed any issues doing things like [tableView reloadData], without dispatching it to the main thread. – tentmaking Dec 01 '17 at 12:14

1 Answers1

9

Since times immemorial Apple has stressed that all interactions with UI elements must happen on the main/GUI thread. Failing to heed that advice would result in weird behavior: sometimes it would work fine, other times it wouldn't. Clearly, now they've changed something to make the behavior more predictable -- it simply doesn't work any more in your specific case and perhaps more generally.

At any rate, I see no reason why one would not simply do what's spelled out in the documentation and ensure that your UI gets updated from the main thread.

dandan78
  • 13,328
  • 13
  • 64
  • 78
  • About time they finally made that change, I had so many bugs where I was like wtf... oh wait this isn't on the main thread. – Kevin DiTraglia Dec 01 '17 at 00:09
  • Is there any documentation on what specific UI updates I should be sending to the main queue? It seems like touches, etc. are by default handled on the main queue, but do I need to present dialog boxes and view views from the main queue? Or is good practice to assume, if UI is being presented or updated, send it to the main queue? – tentmaking Dec 01 '17 at 13:33
  • @tentmaking I added a link to one such place in the docs. The relevant text is in the yellow text box. I have seen similar notes in quite a few places, but since this specific link takes you to the intro page for UIKit, it's probably as good a reference as any. – dandan78 Dec 01 '17 at 14:02