Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TableView doesn't reload when I *replace* its Resource #248

Open
wildthink opened this issue Apr 24, 2018 · 4 comments
Open

TableView doesn't reload when I *replace* its Resource #248

wildthink opened this issue Apr 24, 2018 · 4 comments

Comments

@wildthink
Copy link

Everything works great until I create a new Service (with the same URL) and recreate the wrapping AppAPI (as per your example).

As per the stack overflow I have insured my tableView delegate and dataSource are properly set.

The following resource gets reassigned but the statusOverlay continues to spin and the I don't find any evidence that anything is reloaded.

    var repositoriesResource: Resource? {
        didSet {
            oldValue?.removeObservers(ownedBy: self)

            repositoriesResource?
                .addObserver(self)
                .addObserver(statusOverlay, owner: self)
                .loadIfNeeded()
        }
    }
@axandreo
Copy link
Contributor

@wildthink loadIfNeeded() does not reload the resource unless there's a reason to. Specifically the resource has to be invalidated. If you want a reload from the network, you have to do that sort of manually. There are two ways to handle that:

  1. invalidate the resource, as stated earlier, then call loadIfNeeded:
var repositoriesResource: Resource? {
        didSet {
            oldValue?.removeObservers(ownedBy: self)
            
            repositoriesResource?
                .addObserver(self)
                .addObserver(statusOverlay, owner: self)
                .invalidate
            repositoriesResource?.loadIfNeeded()
        }
    }

Or
2. Tell the resource to load:

var repositoriesResource: Resource? {
        didSet {
            oldValue?.removeObservers(ownedBy: self)

            repositoriesResource?
                .addObserver(self)
                .addObserver(statusOverlay, owner: self)
                .load()
        }
    }

@axandreo
Copy link
Contributor

@wildthink I'm sorry, I misunderstood your question. A tableview doesn't reload unless reloadData is called.

@wildthink
Copy link
Author

Right but shouldn't the statusOverlay be observing the resource? There seems to be a problem/issue with it getting the notification after the resource is changed.

@pcantrell
Copy link
Member

Calling addObserver should send observerAdded regardless of whether you call loadIfNeeded, or whether it actually triggers a load.

Is this with the very latest Siesta release? Could you point at master and see if the behavior still occurs?

It would be helpful if you could either (1) include a minimal test project that exhibits the issue, or (2) include detailed log output tracking all the observers and events. With the new logging API improvements on master, you can do the latter with:

SiestaLog.Category.enabled = .detailed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants