Re: Binding to selection of NSArrayController

2015-02-03 Thread Marek Hrušovský
This sounds like that selection from nstableview is not properly linked.
Make sure that selectionIndex (or something similar) from table is linked
to arraycontroller

On Tue, Sep 23, 2014 at 6:15 PM, Jonathan Taylor 
jonathan.tay...@glasgow.ac.uk wrote:

 Hi all,

 I feel this should be a very simple question, but I am struggling with it
 - the tutorials and online info I can find is either 5 years out of date or
 seem to imply that I am doing everything right!

 In my code I have an NSMutableArray of “message” objects, each with a
 number of properties defined on them. In the GUI this is wired up to a
 table view, via an NSArrayController. That all seems to work fine, and the
 object properties are listed in the table[*].

 Underneath the table I want to display some more detailed information
 about the currently-selected object in the table. I would have thought that
 I could do this just by binding the relevant NSTextField to
 MessageArray.selection.myExtendedInformationProperty. This works up to a
 point, in that I do see text appearing in the text field. However it does
 not update when the selection in the table view changes, which is what I
 had intended to happen.

 This is basically what happens on p18 of this tutorial (
 http://web.stanford.edu/class/cs193e/Downloads/CocoaBindingsTutorial.pdf),
 and (although it’s referring to a much older version of IB) I think I have
 done what they do.

 Can anyone suggest what I may have omitted to do here, or why my approach
 is wrong? Thanks for any advice.
 Cheers
 Jonny.


 [*] One slight glitch - if I add an object to the NSMutableArray then it
 does not immediately show up in the table, I have to call
 will/didChangeValueForKey on the property that returns the array. I don’t
 know if that is expected behaviour (maybe I should be adding via the array
 controller somehow?). This is not a problem, but I mention it for
 completeness, just in case it’s indicative of something funny that is going
 on that I don’t fully appreciate.
 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 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:
 https://lists.apple.com/mailman/options/cocoa-dev/xhruso00%40gmail.com

 This email sent to xhrus...@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Binding to selection of NSArrayController

2014-09-23 Thread Jonathan Taylor
Hi all,

I feel this should be a very simple question, but I am struggling with it - the 
tutorials and online info I can find is either 5 years out of date or seem to 
imply that I am doing everything right!

In my code I have an NSMutableArray of “message” objects, each with a number of 
properties defined on them. In the GUI this is wired up to a table view, via an 
NSArrayController. That all seems to work fine, and the object properties are 
listed in the table[*].

Underneath the table I want to display some more detailed information about the 
currently-selected object in the table. I would have thought that I could do 
this just by binding the relevant NSTextField to 
MessageArray.selection.myExtendedInformationProperty. This works up to a point, 
in that I do see text appearing in the text field. However it does not update 
when the selection in the table view changes, which is what I had intended to 
happen.

This is basically what happens on p18 of this tutorial 
(http://web.stanford.edu/class/cs193e/Downloads/CocoaBindingsTutorial.pdf), and 
(although it’s referring to a much older version of IB) I think I have done 
what they do.

Can anyone suggest what I may have omitted to do here, or why my approach is 
wrong? Thanks for any advice.
Cheers
Jonny.


[*] One slight glitch - if I add an object to the NSMutableArray then it does 
not immediately show up in the table, I have to call will/didChangeValueForKey 
on the property that returns the array. I don’t know if that is expected 
behaviour (maybe I should be adding via the array controller somehow?). This is 
not a problem, but I mention it for completeness, just in case it’s indicative 
of something funny that is going on that I don’t fully appreciate.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Binding to selection of NSArrayController

2014-09-23 Thread Jonathan Taylor
Ah brilliant, that’s fixed it - thanks very much! Makes sense in retrospect 
that I would have to do that, but hadn’t crossed my mind at the time.
Cheers
Jonny

On 23 Sep 2014, at 17:26, Marek Hrušovský xhrus...@gmail.com wrote:

 This sounds like that selection from nstableview is not properly linked. Make 
 sure that selectionIndex (or something similar) from table is linked to 
 arraycontroller
 
 On Tue, Sep 23, 2014 at 6:15 PM, Jonathan Taylor 
 jonathan.tay...@glasgow.ac.uk wrote:
 Hi all,
 
 I feel this should be a very simple question, but I am struggling with it - 
 the tutorials and online info I can find is either 5 years out of date or 
 seem to imply that I am doing everything right!
 
 In my code I have an NSMutableArray of “message” objects, each with a number 
 of properties defined on them. In the GUI this is wired up to a table view, 
 via an NSArrayController. That all seems to work fine, and the object 
 properties are listed in the table[*].
 
 Underneath the table I want to display some more detailed information about 
 the currently-selected object in the table. I would have thought that I could 
 do this just by binding the relevant NSTextField to 
 MessageArray.selection.myExtendedInformationProperty. This works up to a 
 point, in that I do see text appearing in the text field. However it does not 
 update when the selection in the table view changes, which is what I had 
 intended to happen.
 
 This is basically what happens on p18 of this tutorial 
 (http://web.stanford.edu/class/cs193e/Downloads/CocoaBindingsTutorial.pdf), 
 and (although it’s referring to a much older version of IB) I think I have 
 done what they do.
 
 Can anyone suggest what I may have omitted to do here, or why my approach is 
 wrong? Thanks for any advice.
 Cheers
 Jonny.
 
 
 [*] One slight glitch - if I add an object to the NSMutableArray then it does 
 not immediately show up in the table, I have to call 
 will/didChangeValueForKey on the property that returns the array. I don’t 
 know if that is expected behaviour (maybe I should be adding via the array 
 controller somehow?). This is not a problem, but I mention it for 
 completeness, just in case it’s indicative of something funny that is going 
 on that I don’t fully appreciate.
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/xhruso00%40gmail.com
 
 This email sent to xhrus...@gmail.com
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Binding to selection of NSArrayController

2014-09-23 Thread Lee Ann Rucker

On Sep 23, 2014, at 9:15 AM, Jonathan Taylor jonathan.tay...@glasgow.ac.uk 
wrote:
 
 
 
 
 [*] One slight glitch - if I add an object to the NSMutableArray then it does 
 not immediately show up in the table, I have to call 
 will/didChangeValueForKey on the property that returns the array. I don’t 
 know if that is expected behaviour (maybe I should be adding via the array 
 controller somehow?). This is not a problem, but I mention it for 
 completeness, just in case it’s indicative of something funny that is going 
 on that I don’t fully appreciate.

Yes, it’s complicated. The ArrayController doesn’t know about changes that are 
made directly to the NSMutableArray. You can use [NSArrayController addObject:] 
for simple cases, or spend a lot of time with the KVC programming guide, 
especially “Collection accessor patterns for to-many properties”.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Binding to selection of NSArrayController

2014-09-23 Thread Quincey Morris
On Sep 23, 2014, at 11:36 , Lee Ann Rucker lruc...@vmware.com wrote:

 On Sep 23, 2014, at 9:15 AM, Jonathan Taylor jonathan.tay...@glasgow.ac.uk 
 wrote:
 
 [*] One slight glitch - if I add an object to the NSMutableArray then it 
 does not immediately show up in the table, I have to call 
 will/didChangeValueForKey on the property that returns the array. I don’t 
 know if that is expected behaviour (maybe I should be adding via the array 
 controller somehow?). This is not a problem, but I mention it for 
 completeness, just in case it’s indicative of something funny that is going 
 on that I don’t fully appreciate.
 
 Yes, it’s complicated. The ArrayController doesn’t know about changes that 
 are made directly to the NSMutableArray. You can use [NSArrayController 
 addObject:] for simple cases, or spend a lot of time with the KVC programming 
 guide, especially “Collection accessor patterns for to-many properties”.

In fact, Lee Ann is being a little bit kind here, because Jonny really is Doing 
It Wrong™.

Because the UI is using bindings, it is *necessary* to update the array 
KVO-compliantly. Simply adding objects to the NSMutableArray isn’t 
KVO-compliant, hence the lack of automatic updating of the UI.

The underlying problem is in thinking of the data (that is, the “M” in MVC) as 
an array instead of a indexed to-many property. When you make that conceptual 
change, then, yes, you end up in a deep relationship with the KVC programming 
guide.

There is** a quick and dirty way of fixing this, though, without cracking open 
any programming guides. Anywhere that you update the NSMutableArray (either by 
referencing its instance variable “myArray” or “_myArray”, or a property 
“someObject.myArray that provides access to that instance variable), you can 
use a mutable proxy instead. For example, in the class that has the array, 
instead of:

[_myArray addObject: something];

or:

[self.myArray addObject: something];

you would write:

[[self mutableArrayValueForKey: @“myArray”] addObject: something];

and you should magically see the updates start working. But the KVC programming 
guide is a better bet for a long-term relationship.


** Subject to the proviso that I’m just writing this, not doing it ATM, so I 
may have missed something.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Binding to selection of NSArrayController

2014-09-23 Thread Jonathan Taylor
Thankyou both for your advice - it's good to have you set me right on that one. 
Fortunately mine is a relatively uncomplicated case, and so [NSArrayController 
add/removeObject:] should do the job nicely

 It feels a bit odd doing it that way, just because it makes the NSArray almost 
redundant in the whole thing - it's declared as a backing store, but this way I 
don't actually end up accessing it for anything. There's a rather long and 
redundant-seeming chain running from NSArray instance variable - property - 
binding - NSArrayController - IBOutlet - instance variable that I actually 
manipulate. Oh well, if that's the way it's meant to be...


On 23 Sep 2014, at 19:57, Quincey Morris quinceymor...@rivergatesoftware.com 
wrote:

 On Sep 23, 2014, at 11:36 , Lee Ann Rucker lruc...@vmware.com wrote:
 
 On Sep 23, 2014, at 9:15 AM, Jonathan Taylor jonathan.tay...@glasgow.ac.uk 
 wrote:
 
 [*] One slight glitch - if I add an object to the NSMutableArray then it 
 does not immediately show up in the table, I have to call 
 will/didChangeValueForKey on the property that returns the array. I don’t 
 know if that is expected behaviour (maybe I should be adding via the array 
 controller somehow?). This is not a problem, but I mention it for 
 completeness, just in case it’s indicative of something funny that is going 
 on that I don’t fully appreciate.
 
 Yes, it’s complicated. The ArrayController doesn’t know about changes that 
 are made directly to the NSMutableArray. You can use [NSArrayController 
 addObject:] for simple cases, or spend a lot of time with the KVC 
 programming guide, especially “Collection accessor patterns for to-many 
 properties”.
 
 In fact, Lee Ann is being a little bit kind here, because Jonny really is 
 Doing It Wrong™.
 
 Because the UI is using bindings, it is *necessary* to update the array 
 KVO-compliantly. Simply adding objects to the NSMutableArray isn’t 
 KVO-compliant, hence the lack of automatic updating of the UI.
 
 The underlying problem is in thinking of the data (that is, the “M” in MVC) 
 as an array instead of a indexed to-many property. When you make that 
 conceptual change, then, yes, you end up in a deep relationship with the KVC 
 programming guide.
 
 There is** a quick and dirty way of fixing this, though, without cracking 
 open any programming guides. Anywhere that you update the NSMutableArray 
 (either by referencing its instance variable “myArray” or “_myArray”, or a 
 property “someObject.myArray that provides access to that instance 
 variable), you can use a mutable proxy instead. For example, in the class 
 that has the array, instead of:
 
   [_myArray addObject: something];
 
 or:
 
   [self.myArray addObject: something];
 
 you would write:
 
   [[self mutableArrayValueForKey: @“myArray”] addObject: something];
 
 and you should magically see the updates start working. But the KVC 
 programming guide is a better bet for a long-term relationship.
 
 
 ** Subject to the proviso that I’m just writing this, not doing it ATM, so I 
 may have missed something.
 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Binding to selection of NSArrayController manually

2009-03-13 Thread Ivy Feraco

Hello everybody

Bindings problem:

I have an NSArrayController subclass and an NSPopUpButton subclass.
I am trying to bind the NSPopUpButton's selected object to the  
selection of my array controller.

I have to do this manually for reasons I won't get into here.

But when I do this (self is myPopUpButton)
[self bind:@selectedObject toObject:ArrayController  
withKeyPath:@selection options:nil];


I get the error that my array controller is not KVC for the key path  
selection.
selection is definitely a controller key option  in Interface  
Builder, is it possible that this doesn't work programmatically?

Has anyone else run into this problem???

I want to bind to the selected object, not the index... so it seems my  
only option here is selectedObjects, which I will have to pass an  
array of one object to.


Ivy Feraco
UI Developer
i...@boxstudios.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding to selection of NSArrayController manually

2009-03-13 Thread Keary Suska


On Mar 13, 2009, at 9:42 AM, Ivy Feraco wrote:


Hello everybody

Bindings problem:

I have an NSArrayController subclass and an NSPopUpButton subclass.
I am trying to bind the NSPopUpButton's selected object to the  
selection of my array controller.

I have to do this manually for reasons I won't get into here.

But when I do this (self is myPopUpButton)
[self bind:@selectedObject toObject:ArrayController  
withKeyPath:@selection options:nil];


I get the error that my array controller is not KVC for the key path  
selection.
selection is definitely a controller key option  in Interface  
Builder, is it possible that this doesn't work programmatically?

Has anyone else run into this problem???

I want to bind to the selected object, not the index... so it seems  
my only option here is selectedObjects, which I will have to pass an  
array of one object to.



Even if you didn't get the error, this approach wouldn't work. The  
selectedObject must be an exact object from the content collection. - 
selection returns a proxy object. You might try barking up using  
selectedValue instead. But then, you might still have the binding  
error, or it might go away since you are binding through selection.  
Anyway, have you verified that the ArrayController variable is what  
you expect it to be at the point that bind: is called?


HTH,

Keary Suska
Esoteritech, Inc.
Demystifying technology for your home or business

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding to selection of NSArrayController manually

2009-03-13 Thread Stuart Malin


On Mar 13, 2009, at 9:42 AM, Ivy Feraco wrote:


I have an NSArrayController subclass and an NSPopUpButton subclass.
I am trying to bind the NSPopUpButton's selected object to the
selection of my array controller.
I have to do this manually for reasons I won't get into here.

But when I do this (self is myPopUpButton)
[self bind:@selectedObject toObject:ArrayController
withKeyPath:@selection options:nil];

I get the error that my array controller is not KVC for the key path
selection.
selection is definitely a controller key option  in Interface
Builder, is it possible that this doesn't work programmatically?
Has anyone else run into this problem???

I want to bind to the selected object, not the index... so it seems my
only option here is selectedObjects, which I will have to pass an
array of one object to.


I'm no expert in this area, but have dabbled with some code related to  
this, hence I offer the following subject to proviso...


I believe the only KVObservable properties of NSArrayController that  
you can use in this way are: -selectedObjects, -selectionIndex, and - 
sectionIndexes.


My suggestion, as you have subclassed NSArrayController, would be to  
add an additional KVO compliant property that returns the underlying  
(first) selected object (not the proxy object). Implement a - 
selectedObject property in your sub class and use it as the keyPath in  
the bind statement.


- (id) selectedObject
{
return [[self selectedObjects] objectAtIndex:0];
}

HTH.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding to selection of NSArrayController manually

2009-03-13 Thread Ivy Feraco

Yes thanks
I did something like this.
I realize now that selection is just a getter method on  
NSObjectController

so no sense binding to it without a keypath.


Ivy Feraco
UI Developer
i...@boxstudios.com

On Mar 13, 2009, at 2:34 PM, Stuart Malin wrote:



On Mar 13, 2009, at 9:42 AM, Ivy Feraco wrote:


I have an NSArrayController subclass and an NSPopUpButton subclass.
I am trying to bind the NSPopUpButton's selected object to the
selection of my array controller.
I have to do this manually for reasons I won't get into here.

But when I do this (self is myPopUpButton)
[self bind:@selectedObject toObject:ArrayController
withKeyPath:@selection options:nil];

I get the error that my array controller is not KVC for the key path
selection.
selection is definitely a controller key option  in Interface
Builder, is it possible that this doesn't work programmatically?
Has anyone else run into this problem???

I want to bind to the selected object, not the index... so it seems  
my

only option here is selectedObjects, which I will have to pass an
array of one object to.


I'm no expert in this area, but have dabbled with some code related  
to this, hence I offer the following subject to proviso...


I believe the only KVObservable properties of NSArrayController that  
you can use in this way are: -selectedObjects, -selectionIndex, and - 
sectionIndexes.


My suggestion, as you have subclassed NSArrayController, would be to  
add an additional KVO compliant property that returns the underlying  
(first) selected object (not the proxy object). Implement a - 
selectedObject property in your sub class and use it as the keyPath  
in the bind statement.


- (id) selectedObject
{
return [[self selectedObjects] objectAtIndex:0];
}

HTH.




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com