• 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: Binding my custom view to NSArrayController's arrangedObjects (was) not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binding my custom view to NSArrayController's arrangedObjects (was) not working


  • Subject: Re: Binding my custom view to NSArrayController's arrangedObjects (was) not working
  • From: Yann Bizeul <email@hidden>
  • Date: Tue, 8 May 2007 22:52:14 +0200

Well this is not a mater of observing the value, after mmalc explications I understood the difference between he's tutorial you pointed and the one I found here : http://www.bignerdranch.com/ palettes/x342.htm

in 10.4, there is a new method to inspect binding, which avoid overriding bind: method, but you still have to notify observed controllers yourself, but it is quite simple (a small category to NSObject handles that quite easily).

I checked that by subclassing arraycontroller, and indeed, NSObject's default implementation of bind:... does register self as an observer for the bound values.

Thanks for your reply.

Yann Bizeul - yann at tynsoe.org
Cocoa Developer

Tynsoe Projects
BuddyPop - GeekTool - SSH Tunnel Manager - ...
http://projects.tynsoe.org/


Le 8 mai 07 à 22:43, Dominik Pich a écrit :

Well,... i'd not copy it but instead override bind/unbind so you observe the bound key path... it makes the view more complex but could be more efficient?!
As im no binding guru though, please share the right way to do it one of you!


I followed the tutorials at http://homepage.mac.com/mmalc/ CocoaExamples/controllers.html

Regards,
Dominik

On May 8, 2007, at 10:25 PM, Yann Bizeul wrote:

Hello (again)

Ok, once the problem is solved, I really felt I *must* share that with others, especially bindings gurus around and peoples thinking that bindings are really obvious.

Talking about obvious things, I just wanted to bind my CustomView to MyArrayController's arrangedObjects.

So, in my document's windowControllerDidLoadNib, I do :

	[framesMatrix  bind:@"contentFrames"
			   toObject:frames
			withKeyPath:@"arrangedObjects"
				options:nil];

frames is the outlet to the NSArrayController in nib

Ok, now, I just have to implement accessors in my view. right ? Let's go :

- (void)setContentFrames:(NSArray*)anArray {
	NSLog(@"Test");
	[self willChangeValueForKey:@"contentFrames"];

	[anArray retain]  // Hey, bookmark this line for later in the post
	[contentFrames autorelease];
	contentFrames = anArray;
	[...]
	[self didChangeValueForKey:@"contentFrames"];
}

- (NSArray*)contentFrames {
	return contentFrames;
}

OK, now compile and run.

========= LONG DAY OF DEBUGGING STARTING HERE ========= (option KidAndWifeAround enabled)

The problem is setContentFrames: was only called once, when creating the binding, and never afterwhile.

Like always with bindings, I tested different keys, different keypath, etc, etc without success.
Well, In fact, it was partially working because a simple NSTextField in my window bound to "myArrayController" "arrangedObjects" "@count" was updating itself just fine.


Guess what's wrong ? I learned here that for some reasons (that could be good, but not so obvious) we should ***NEVER*** retain the NSArrayController's arrangedObjects array passed as argument.

As soon as I removed that (i.e. make a copy instead of retain) everything works fine.

Who says bindings is less code and less time ?

(Yeah, I know the whole "binding is cool for appkit stuffs" and so on... but it is like a drug, i can't avoid those dark days each time I start a project when I want to use bindings because it seems so powerfull...)

Anyways, if some bindings guru read this post, I would be glad to have an explanation (mmalc ?)

Thanks

Yann Bizeul - yann at tynsoe.org
Cocoa Developer

Tynsoe Projects
BuddyPop - GeekTool - SSH Tunnel Manager - ...
http://projects.tynsoe.org/


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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)

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: 
 >Binding my custom view to NSArrayController's arrangedObjects (was) not working (From: Yann Bizeul <email@hidden>)

  • Prev by Date: Binding my custom view to NSArrayController's arrangedObjects (was) not working
  • Next by Date: Weird PDFView Printing Issue
  • Previous by thread: Binding my custom view to NSArrayController's arrangedObjects (was) not working
  • Next by thread: Weird PDFView Printing Issue
  • Index(es):
    • Date
    • Thread