0

I have a view controller with two table views in it and all their data comes from a single object. The second table view has a TextView in it that I can use to change the model object. When I enter text in the TextView, the top TableView (without the text field) updates, but not the bottom.

Before Edits: Before Edits

After Edits: After Edits Minimum Code Reproduction: Github Repo

7
  • 1
    Many possible reasons - you need to do a little debugging. Is .reloadData() actually being called? If so, is the proper cellForRowAt being called? If so, does the data you're giving to the cell reflect the change? If so, is whatever's going on in the cell class to display the data executing correctly? If the answer to any of those "if so" questions is no - that's where to look for the problem. Commented Feb 3, 2022 at 18:46
  • 1
    Yeah, this is going to depend on your specific implementation, and will require you do some detailed debugging. If you want help debugging it you're going to need to either post a whole bunch of code or create a minimal example project that reproduces the problem, put it on Github, and post a link as part of your question. Commented Feb 3, 2022 at 19:15
  • Darn. I was hoping that that would be enough information. Btw, reloadData() is being called and cellForRowAt is being called with all the other tables views, but not the specific one I've mentioned(but only in some cases). I've spent several hours debugging and I'm a little stumped at what to try next. Commented Feb 3, 2022 at 19:43
  • @developerextraordinare - as Duncan said, see if you can create a minimal reproducible example and put it on GitHub. You say "... being called with all the other tables views ..." but that doesn't make sense, unless .reloadData() is being called on "the other table views" from somewhere else. Commented Feb 4, 2022 at 14:09
  • @DonMag I created a minimum example removing 95%+ of my code, but It is still a fairly large project. Any ideas to strip it down further? Also, I added a link to the code above. Commented Feb 4, 2022 at 21:29

1 Answer 1

1

Tough to say what exactly is causing the problem, but it seems to be a timing issue.

In ViewController, change your didSet to this:

var timecard: Timecard? {didSet {
    if self.isViewLoaded {
        DispatchQueue.main.async {
            self.employeeTableView.reloadData()
            self.timecardTableView.reloadData()
        }
    }
}}

In your minimal example, that seems to fix the issue.

Without spending a lot more time on it, my guess would be that you've got a closure that's holding onto the cell being edited, preventing the table view from reloading? Maybe something similar to that.

On a side note -- you've got some rather unusual stuff going on. Generally a bad idea to assign things like this:

weak var viewController: ViewController?

And, it looks like your closures could be problematic in a couple ways (row index can change, looks like you're creating strong references that can cause retain cycles, etc).

Sign up to request clarification or add additional context in comments.

1 Comment

To your side note: It's part of a larger project that uses the coordinator pattern for navigation and "pushes" view models instead of view controllers so that views can be used with multiple view models. So in this context it does look very strange. Honestly, even in the parent project it is a little funky and I don't love it, but I don't have much say on that part. Thanks for taking a look at it. That band aid fix works for now. Also... You are totally right about the retain cycles. I'll get on those.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.