siesta icon indicating copy to clipboard operation
siesta copied to clipboard

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

Open wildthink opened this issue 6 years ago • 4 comments

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()
        }
    }

wildthink avatar Apr 24 '18 03:04 wildthink

@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 avatar Jun 23 '18 01:06 axandreo

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

axandreo avatar Jun 23 '18 15:06 axandreo

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.

wildthink avatar Jun 23 '18 15:06 wildthink

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

pcantrell avatar Jun 24 '18 16:06 pcantrell