MVC: How best avoid nested invocations of -reloadData?
MVC: How best avoid nested invocations of -reloadData?
- Subject: MVC: How best avoid nested invocations of -reloadData?
- From: Jerry Krinock <email@hidden>
- Date: Mon, 9 Jun 2008 11:46:55 -0700
My data objects are viewed in an NSOutlineView, and additional
attributes of the selected item appear in an Inspector panel.
I have tried to implement MVC by funneling any data-model property
change in any view to send a -changeObjectProperty::: message which
updates the model, registers undo and sends an -updateWindow message
to all existing window controllers. Since the outline is editable, my
dataSource's implementation of
outlineView:setObjectValue:forTableColumn:byItem: does this. To
update the outline, the window controller of the window containing the
outline view sends the outline view a -reloadData in its -updateWindow
implementation.
There is a tiny problem if the user begins editing a value in the
outline view and then, while the field editor is still key, switches
to the Inspector panel and edits another attribute. Method
changeObjectProperty::: runs for the other attribute, eventually
sending -reloadData to the outline view. Apparently, -reloadData
tells the outline view to end editing, which sends
outlineView:setObjectValue:forTableColumn:byItem: to the data source,
which invokes changeObjectProperty::: again, which sends -updateWindow
again, which sends -reloadData again. Actually, it all works great,
except I get this in the console:
"NSOutlineView Warning: reloadData called while in the middle of
doing a reloadData!"
Which is indeed true. Interestingly, this does not happen if editing
the other attribute in the Inspector panel grabs the field editor. In
that case, the edit in the outline view is ended and its -reloadData
is completed before the other edit begins. The problem only occurs if
the other edit is done in a non-text control such as a checkbox.
I've solved the problem by adding a BOOL _isReloadingData to my window
controller and locking it so that any attempted -nested invocation of -
reloadData is skipped. Is there a less hacky solution? Or have I mis-
conceived MVC somewhat? (I now know that a notification would be more
elegant and bug-resistant than sending a bunch of -updateWindow
messages, but I don't think that would change this issue.)
Thanks,
Jerry Krinock
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden