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

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


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

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


  • Prev by Date: NSScrollView Resize Problems
  • Next by Date: Re: Binding my custom view to NSArrayController's arrangedObjects (was) not working
  • Previous by thread: NSScrollView Resize Problems
  • Next by thread: Re: Binding my custom view to NSArrayController's arrangedObjects (was) not working
  • Index(es):
    • Date
    • Thread