• 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: Bindings/KV Too Magical
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bindings/KV Too Magical


  • Subject: Re: Bindings/KV Too Magical
  • From: Chase Meadors <email@hidden>
  • Date: Sun, 2 Aug 2009 23:14:26 -0500


On Aug 2, 2009, at 8:07 PM, Gregory Holden wrote:

Some n00b questions about Bindings/KV I'm facing:

1) NSArrayController and canRemove, how does it know?
A familiar example to those who ran through Aaron Hillegass' Learning Cocoa Programming.


I have an NSArrayController, an NSButton, and an NSTableView
- NSArrayController's contentArray is an NSMutableArray in a MyDocument class.
- NSButton sends the action 'remove:' to the NSArrayController on click
- The column in NSTableView has a binding to NSArrayController to display 'arrangedObjects.personName'


The last piece is the magical piece that is driving me nutty. The NSButton has a binding enabled = NSArrayController's -(BOOL)canEnable.
I can't figure out how the NSArrayController knows when the NSTableView has a row selected.



I'm guessing you mean the array controllers -canRemove: method. You're kind of thinking backwards here.


NSArrayController manages an array and everything about it. This means NSArrayController keeps track of all its objects, which of its objects are "selected," and updates properties like canRemove based on this data.

The NSArrayController does not ask the table view what rows it has selected; rather, the NSArrayController makes changes to its properties which the table view then observes.

So you your button is disabled when there are no selections because NSArrayController, not the table view, has no selections, and updates its canRemove property.

Hope this makes sense.

---------------------
2) requires 'insertObject:in<key>AtIndex' for 'removeObjectFrom<key>AtIndex' to work
If I don't implement 'insertObject:in<key>AtIndex' then 'removeObjectFrom<key>AtIndex' is never called. Why? The only reason I can come up with is possibly a shortcut in Cocoa that if insert is not implemented then remove probably isn't either.
Which bring me to my next question, how does it know the insert is implemented?
I overrode:
-(BOOL)respondsToSelector:(SEL)aSelector
but it never queries for the insert. What magic does it work with?

I'm afraid I can't answer that one, but many people here can.


Any help is GREATLY appreciated. I hate magic and I can't seem to figure out the under-workings.


Thanks
G
_______________________________________________

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

_______________________________________________

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


References: 
 >Bindings/KV Too Magical (From: Gregory Holden <email@hidden>)

  • Prev by Date: Re: How to set the name of open-with application for a specific file?
  • Next by Date: Re: Bindings/KV Too Magical
  • Previous by thread: Bindings/KV Too Magical
  • Next by thread: Re: Bindings/KV Too Magical
  • Index(es):
    • Date
    • Thread