OK, so after coming back to this issue, I have discovered some new things:
- When we receive a presence update of 'unavailable', we remove the resource object associated with it.
- Obviously this resource object contains some information which I use in my table (the status field)
- Testing to see if the status resource is nil after the presence update, I get nil, which I understand as the resource having been correctly deleted.
- After the presence update to unavailable, the roster item DOES have the correct sectionNum (2), but continues to reside in its old section (0 or 1).
- In 'titleForHeaderInSection', the number of sections returned by the fetchedResultsController is incorrect. I tested this with a roster of 2 items:
1. both items start off as offline. --> numberOfSections is 1
2. roster item 1 comes online. --> numberOfSections is 2
3. roster item 1 goes offline. --> numberOfSections is 2 (obviously incorrect)
Just to refresh your memory, the above occurs when ANY attempt at reading the resource is made.
This even happens if testing "if (user.primaryResource != nil)" before any further reading is done!
I am performing these reads in cellForRowAtIndexPath.
I am completely at a loss as to why this is occurring. The only thing I can think of is that by reading the value from the resource object somehow keeps a strong pointer to the viewcontroller, so when it is "deleted", it isn't really deleted because the persistentcoordinator thinks there is something still 'using' it. I even set the cell label's text to nil to ensure that its not pointing to anything if it detects a user with a nil primaryResource.
if (user.primaryResource != nil) cell.detailTextLabel.text = user.primaryResource.status;
else cell.detailTextLabel.text = nil;
I hope I'm providing enough information here. Unfortunately, I am still an amateur when it comes to CoreData, so trying to trace the steps is quite a challenge.
As far as I can see, it is simple enough to reproduce. All you need to to simply read a roster item's resource. Then, on the other device, go 'unavailable', and hopefully you'll see the item stuck in the wrong section. (funny how you say hopefully in the case of producing a reproducible bug).
Regards,
Niems