0

I have the following method on my table view controller class:

func reloadInputFields() {
    dispatch_async(dispatch_get_main_queue()) {
        self.tableView.beginUpdates()
        self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: .Automatic)
        self.tableView.endUpdates()
    }
}

This is called from an NSNotification. The runtime enters this method fine and appears to call reloadSections. However it never actually does. Obviously I am executing on the main thread here as it is a UI update but I have also tried on a background thread. I have also tried just calling tableView.reloadData() instead of reloadSections but no joy there. The table view definitely exists and I have checked that the pointer is correct.

Breakpoints in cellForRowAtIndexPath numberOfSectionsInTableView heightForRowAtIndexPath numberOfRowsInSection etc are not being hit and the table is not reloading.

My delegate and dataSource are set correctly as verified here:

enter image description here

I've been struggling with this for several hours now and it's totally bested me. Any suggestions would be gratefully received.

Jacob King
  • 6,025
  • 4
  • 27
  • 45
  • is number of row in section called ? – Prashant Tukadiya Oct 03 '16 at 08:36
  • No it is not Mike, should have listed that one as well. – Jacob King Oct 03 '16 at 08:38
  • check delegate first, and if you are drag & drop the table no need to alloc the tableview try it once. – seggy Oct 03 '16 at 08:39
  • Please, show your code as much as possible. – Vyacheslav Oct 03 '16 at 08:40
  • Why has this question been downvoted and voted for closure? – Jacob King Oct 03 '16 at 08:42
  • Vyachelav, what more do you want to see? It's pretty clear what I am struggling with, I see no reason to paste all of my tableView delegate and datasource methods when they are not even being called? – Jacob King Oct 03 '16 at 08:44
  • Sathi, I am sending said notification from the a textfield object on one of the cells in the table. I do have a reference to the tableView in that same object and have tried calling it directly but no joy there either. – Jacob King Oct 03 '16 at 08:53
  • Deep down in a subview tree, potentially yes. But it seems that the notification is not the issue as the `reloadInputFields` method is invoked fine. – Jacob King Oct 03 '16 at 08:55
  • I will write an answer with suggestions,please follow until it works. But remove the comments after our discussion. Otherwise, it will make the page clumsy. – KSR Oct 03 '16 at 09:01
  • @Jacob King Please post the screenshot of ViewController, i will give you sample project.. – KSR Oct 03 '16 at 09:36
  • Sathi, I would need to send you about 8 files worth of code as the various responsibilities are delegated to view models, cells, models managers etc... If it comes to it I will put a sample project together myself and link it. Thanks for offering though. – Jacob King Oct 03 '16 at 09:38
  • Probably not a solution but `begin / endUpdates()` is not needed at all. – vadian Oct 03 '16 at 10:29
  • Thanks for the suggestion vadian but alas no, I have tried without and no joy. :( – Jacob King Oct 03 '16 at 10:43
  • lastly , if you still not able to do it , check clips to bounds of superview of tableview and make it true , check table frame, reset delegate datasource, check array – Prashant Tukadiya Oct 04 '16 at 07:19

2 Answers2

2

Some suggestions to solve this issue:

1. Make sure you have IBOutlet connection to the UITableView.

2. Check delegate and datasource. If necessary, write them programmatically.

3. Make sure your tableView is populated with data before triggering notification.

4. Avoid beginUpdates and endUpdates and use only reloadData on main thread.
KSR
  • 1,699
  • 15
  • 22
0

Is the table view active when the notification is fired? Check if the table view controller is released (It is not active. Probably not shown on the screen)

sushma
  • 9
  • 3
  • Thanks for the suggestion but the notification is sent from a text field in one of the cells of the table view, meaning the tableview is on screen. – Jacob King Oct 03 '16 at 11:47
  • check if your problem is similar to this : http://stackoverflow.com/questions/26758101/table-view-reload-sections-crashes – sushma Oct 03 '16 at 11:58