siesta
siesta copied to clipboard
TableView doesn't reload when I *replace* its Resource
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 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:
- 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()
}
}
@wildthink I'm sorry, I misunderstood your question. A tableview doesn't reload unless reloadData
is called.
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.
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