CPArrayController addObject: causes warning log statements when bound to CPTableView

102 views
Skip to first unread message

KC

unread,
Feb 2, 2012, 11:45:01 AM2/2/12
to Cappuccino & Objective-J
I'm having a problem using bindings with CPTableView and
CPArrayController (Cappuccino framework is version 0.9.5).
I have an CPArrayController instance bound to a CPTableView instance
with its columns bound to properties of the class of objects contained
in the array controller's content array.

The bindings seem to work but when I use addObject on the
CPArrayController instance however it prints out CPLog.warn statements
about 'Cannot remove an observer' .

The following sample code results in the following warning statements:

Cannot remove an observer <$KVO_Item 0x0048eb> for the key path "bar"
from <_CPKVOForwardingObserver 0x004430> because it is not registered
as an observer.
Objective-J.js (line 432)
Cannot remove an observer <$KVO_Item 0x0048ec> for the key path "bar"
from <_CPKVOForwardingObserver 0x004430> because it is not registered
as an observer.
Objective-J.js (line 432)

The warnings do not appear for the first column that was bound.

Test Code follows:
------------------------------------------------------------------------------------------------------------
@import <Foundation/CPObject.j>

@implementation Item : CPObject
{
CPString foo @accessors;
CPString bar @accessors;
}

@end

@implementation AppController : CPObject
{
CPArrayController controller;
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc]
initWithContentRect:CGRectMakeZero()
styleMask:CPBorderlessBridgeWindowMask];
var contentView = [theWindow contentView];

var frame = CGRectMake(0, 0, CGRectGetWidth([contentView bounds]),
CGRectGetHeight([contentView bounds]));

controller = [[CPArrayController alloc] init];
var item0 = [[Item alloc] init];
[item0 setFoo:@"Foo 0"];
[item0 setBar:@"Bar 0"];
[controller setContent:[CPArray arrayWithObject:item0]];

var table = [[CPTableView alloc] initWithFrame:frame];
[table setAutoresizingMask:CPViewWidthSizable |
CPViewHeightSizable];
[table setUsesAlternatingRowBackgroundColors:YES];
[table setTarget:self];
[table bind:@"content" toObject:controller
withKeyPath:@"contentArray"
options:nil];


var fooColumn = [[CPTableColumn alloc] initWithIdentifier:@"foo"];
[[fooColumn headerView] setStringValue:@"Foo"];
[fooColumn bind:CPValueBinding toObject:controller
withKeyPath:@"arrangedObjects.foo" options:nil];
[table addTableColumn:fooColumn];

var barColumn = [[CPTableColumn alloc] initWithIdentifier:@"bar"];
[[barColumn headerView] setStringValue:@"Bar"];
[barColumn bind:CPValueBinding toObject:controller
withKeyPath:@"arrangedObjects.bar" options:nil];
[table addTableColumn:barColumn];

var scrollView = [[CPScrollView alloc] initWithFrame:frame];
[scrollView setAutoresizingMask:CPViewWidthSizable |
CPViewHeightSizable];
[scrollView setDocumentView:table];
[contentView addSubview:scrollView];

[theWindow orderFront:self];

var item1 = [[Item alloc] init];
var item2 = [[Item alloc] init];

[controller addObject:item1];
[controller addObject:item2];

[item1 setFoo:@"Foo 1"];
[item1 setBar:@"Bar 1"];

[item2 setFoo:@"Foo 2"];
[item2 setBar:@"Bar 3"];
}
@end
------------------------------------------------------------------------------------------------------------

ah14

unread,
Feb 10, 2012, 2:09:03 PM2/10/12
to Cappuccino & Objective-J
Hi,

I seem to be having the same issue. No warnings showed up while I was
working off of the 0.9.0 tag, but now after updating my development to
the 0.9.5 tag, I keep getting this warning message.

I too am binding to my tables in this way; are there different options
that need to be set on the array controller or table view in order to
keep these messages from coming up, or is there a different way I
should be matching array controller content to a table view?

~Anna

Alexander Ljungberg

unread,
Feb 10, 2012, 3:06:52 PM2/10/12
to objec...@googlegroups.com
Hello,

There are a few simple changes you might want to try with your code. First, add table columns to the table before binding them. Second, don't make the "content" binding by hand. This will be done automatically assuming you follow the first step.

So in terms of your code:

1. Remove `[table bind:@"content" toObject:controller withKeyPath:@"contentArray" options:nil];`
2. Flip the order of `[fooColumn bind:CPValueBinding toObject:controller withKeyPath:@"arrangedObjects.foo" options:nil];` and `[table addTableColumn:fooColumn];`.

Alexander

> --
> You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
> To post to this group, send email to objec...@googlegroups.com.
> To unsubscribe from this group, send email to objectivej+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/objectivej?hl=en.
>

KC

unread,
Feb 10, 2012, 6:34:32 PM2/10/12
to Cappuccino & Objective-J
Hi,

Thank you for the suggestions. I modified my code as you said, but
unfortunately I get the same warning messages as before.

Kerri

Jeremy Savoy

unread,
Apr 5, 2012, 10:29:05 PM4/5/12
to objec...@googlegroups.com
I see this same issue. If you download the CPArrayController CIB example from Headz blog from 12/2011 and run his code with the included version of Capp, it works as expected. If you remove his Frameworks folder and link in the most recent build of Cappuccino, you see this exact error. Very simple to reproduce.

Here is the link to his tutorial, with a link to the code at the bottom:
> > To unsubscribe from this group, send email to objectivej+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages