• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Bindings and the Undo Manager (again)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings and the Undo Manager (again)


  • Subject: Bindings and the Undo Manager (again)
  • From: Dan Stein <email@hidden>
  • Date: Sat, 29 Jan 2005 23:01:30 -0800

Bindings is now getting along better with the Undo Manager in my app. (Woo - hoo!)

I'm rebuilding from scratch and have installed the Undo Manager - related routines
as early as possible, working as closely as I can from the Raise Man (bindings) example from Hillegass' book.

For quite some time today I was getting errors upon trying to undo an insert operation into my table (even though undoing
deletions and edits seemed to be working OK):

2005-01-29 22:15:01.009 BookBindery[3348] *** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)

Or whatever the index was of the row I was trying to undo. And further array operations would eventually lead to

2005-01-29 22:15:13.231 BookBindery[3348] undo: NSUndoManager 0x38b5d0 is in invalid state, undo was called with too many nested undo groups

Eventually (and there really was NO other part of my project left to inspect for glitches) I traced it to the fact that I had
left the attributes for my Array Controller with the "Preserves Selection" switch turned ON in IB.

I don't actually own the Second Edition of Hillegass' book, I just have the first - so
all I have to pursue this is a working Xcode project with the Raise Man example in it.
I note in my version of this project that, in fact, the "Preserves Selection" switch is turned OFF. This is how I finally
discovered the solution to the problem - I compared everything else I could find. And this was not purely trivial, since
my project implements a window controller subclass, and Hillegass' example does not. I subclass the
Array Controller, and Hillegass does not. My undo code is of necessity in the window controller (the nib file's owner)
whereas Hillegass puts his in the document class (and you will tell me I should never have considered these issues!)
When all was said and done, my source code was flawless for the task I had set.

Is there some documentation of why this is such a critical setting? Hillegass' example stops working in exactly the
same way if I turn on "preserves selection" there, so it could be an idiosyncrasy of the coding particulars that I
am emulating. For anyone with the book: Does Hillegass specifically mention the importance of this setting?

For those who don't have the example handy, the undo behavior for rows is supported by the following methods:

- ( void ) insertObject: ( Person * ) p inEmployeesAtIndex: ( int ) index;
- ( void ) removeObjectFromEmployeesAtIndex: ( int ) index;

- ( void ) startObservingPerson: (Person * ) p;
- ( void ) stopObservingPerson: ( Person * ) p;

and for undoing individual cell edits

- ( void ) changeKeyPath: ( NSString * ) keyPath ofObject: ( id ) obj toValue: ( id ) newValue;
- ( void ) observeValueForKeyPath: ( NSString * ) kp ofObject: ( id ) obj
change: ( NSDictionary * ) change context: ( void * ) con;

There's an array in the document class or window controller that you bind to the Array controller's content array.
Rather than inundate you with code, I await additional feedback.

Cheers,

Danl
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Bindings and the Undo Manager (again)
      • From: Jason Harris <email@hidden>
    • Re: Bindings and the Undo Manager (again)
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Re: Do IMPs move once they're loaded?
  • Next by Date: Re: Do IMPs move once they're loaded?
  • Previous by thread: RE: Default Nib on Document based apps
  • Next by thread: Re: Bindings and the Undo Manager (again)
  • Index(es):
    • Date
    • Thread