Reputation: 8664
There are a lot of questions and answers on this topic but I could not find one for this situation.
The app has been in production for about 3 years so I'm confident that the table view in question and all the other table views are already wired up correctly. I'm adding a new feature and I'm encountering something I didn't expect.
Here's the situation:
reloadData:
.numberOfRowsInSection:
gets called and returns the correct number of rows. Up to this point everything is working exactly like I'd expect. But that's where it stops. After numberOfRowsInSection:
there is nothing else. cellForRowAtIndexPath:
is not called.
Obviously, the table view I'm reloading is not visible. It's on another tab.
Is this behaviour is an optimization where reloadData
is simply not executed because the table isn't visible? Can anyone confirm this?
Upvotes: 0
Views: 184
Reputation: 1844
As Duncan points out a VC will not reload the tableView unless it is in the current view hierarchy. I've recently been working on an app which uses a lot of KVO for updating tableViews, and the best solution I could come up with was simply to mark the view as dirty by having a property BOOL needsRedraw on the viewController in question. Then when viewWillAppear: is called in that viewController you should be able to reload the tableview
Upvotes: 1
Reputation: 131426
This makes perfect sense to me, except the part where your table view calls numberOfRowsInSection:. I would not expect that when the VC is not visible.
If the table view is not in the current view hierarchy it won't draw.
Upvotes: 4