• 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
Re: Custom canRemove binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom canRemove binding


  • Subject: Re: Custom canRemove binding
  • From: Chris Giordano <email@hidden>
  • Date: Wed, 5 May 2004 09:41:03 -0400

Ian,

On May 5, 2004, at 8:26 AM, ian wrote:

Hello,

I'm using an NSArrayController to populate a tableview according to the contents of an array of objects in an instance of MyDocument for a doc based app.

I've got add/insert/remove buttons set up and the add/insert are enabled by binding to the array controller's selection - canAdd and canInsert.

I'd like to prevent the user from deleting the last row in the table however, so I bound the remove button to File's Owner (MyDocument) and a model key path of "myCanDelete" which is the name of a method that returns ([theArray count]>1)

Trouble is, this is called once only at startup, so the button doesn't update.


Any ideas before I go ahead and subclass NSArrayController to override canRemove?

Just going though the same thing, so I can sympathize.

No need to subclass the controller here. You just need to make sure that the controller hears that the value of your myCanDelete key path has changed when appropriate. Since it's derived from your array's count and that probably isn't set via key value coding, that isn't happening yet.

What you can do is add these two lines (or something that calls these two lines) to all methods that could change the value of [theArray count] (i.e., when you add, insert or delete):

// Assuming you're in the MyDocument class. Other places will require
// your myDocument object instead of "self"
[self willChangeValueForKey:@"myCanDelete"];
[self didChangeValueForKey:@"myCanDelete"];


Another thing that you can do is to create another "enabled" binding to something that is updated when you want this to be triggered as well. So, for example, if you wanted to disable the delete button when no item was selected in the table view, you could also bind "yourController.selection" to your button's "enabled2" binding (with a NSIsNotNil Value Transformer) and your myCanDelete method will also be called when the selection changes. (At least this is the case in my experience.)

chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Custom canRemove binding (From: ian <email@hidden>)

  • Prev by Date: SOLVED: The position of the insertion point in an NSTextView?
  • Next by Date: Re: Custom canRemove binding
  • Previous by thread: Custom canRemove binding
  • Next by thread: Re: Custom canRemove binding
  • Index(es):
    • Date
    • Thread