NSCollectionView item crashes when bound
NSCollectionView item crashes when bound
- Subject: NSCollectionView item crashes when bound
- From: Benjamin Rindt <email@hidden>
- Date: Mon, 16 Sep 2013 20:16:32 +0200
Hey guys I'm really grinding with the NSCollectionView when its bound. I had a running collection view but wanted to use bindings, I looks like it should work, but it doesn't. This is written just in code not in IB.
Hope you guys can help :)
The problem is, the View is displayed correctly, but as soon as I try to bind a property in the newItemForRepresentedObject method, it is trying to call setChannelID (I can see it in the console outputting "hello" all the time, but keeps stuck in the else part of the if statement. It never gets to make the if true, always trying to set it. There is no output after the self.channelID = chanID; command, there is just another hello. I think the ChannelView property is not holding the data. The program crashes after 10 seconds trying to set the value. It should be possible to do this, others have obviously bound in the newItemForRepresentedObject.
Anyway, any help is appreciated this is the code:
ChannelView
#import <Cocoa/Cocoa.h>
@interface ChannelView : NSView
@property (readwrite, nonatomic, copy) NSString *channelName;
@property (readwrite, nonatomic, copy) NSNumber *channelID;
@property (readwrite) NSTextField *channelNameField;
@property (readwrite) NSTextField *deviceChannelField;
@end
@implementation ChannelView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:NSMakeRect(0, 0, 300, 500)];
if (self) {
// Initialization code here.
ColorView *test = [[ColorView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
self.channelNameField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20)];
self.deviceChannelField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 50, 100, 20)];
[self addSubview:test];
[self addSubview:self.channelNameField];
[self addSubview:self.deviceChannelField];
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
//add die teile
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
}
// setters.
-(void)setChannelID:(NSNumber *)chanID
{
//NSLog(@"hallo");
if (self.channelID == chanID) {
return;
NSLog(@"da");
}
else {
NSLog(@"hello"); //just this in debug output
//self.channelID = [chanID copy];
NSLog(@"no output");
self.channelID = chanID;
NSLog(@"chanid %d current: %d", chanID.intValue, self.channelID.intValue); //never shown in debug
[self.deviceChannelField setStringValue:[NSString stringWithFormat:@"%d",self.channelID.intValue]];
}
}
@end
The piece of my subclassed NSCollectionView
- (NSCollectionViewItem *)newItemForRepresentedObject:(ChannelsToMixes*)object
{
NSCollectionViewItem *item = [super newItemForRepresentedObject:object];
// ChannelView *view = (ChannelView *)[item view];
NSLog(@"cahnnelid: %d",object.channelID.intValue);
// [view bind:@"title" toObject:object withKeyPath:@"title" options:nil];
[item.view bind:@"channelID" toObject:object withKeyPath:@"channelID" options:nil];
//NSLog(@"test");
//NSLog(@"%@",object);
return item;
}
self.collectionView = [[ChannelCollectionView alloc] initWithFrame:NSMakeRect(10, 0, width, self.splitview.frame.size.height)];
[self.collectionView setItemPrototype:[ChannelViewItemController new]];
[self.collectionView setMaxNumberOfRows:1];
[self.collectionView setAutoresizingMask:(NSViewMinXMargin | NSViewWidthSizable | NSViewMaxXMargin | NSViewMinYMargin | NSViewHeightSizable| NSViewMaxYMargin)];
[self.collectionView setAutoresizesSubviews:YES];
[self.collectionView bind:NSContentBinding toObject:self.channelController withKeyPath:@"arrangedObjects" options:nil];
ChannelViewItemController:
@implementation ChannelViewItemController
-(void)loadView {
[self setView:[[ChannelView alloc] initWithFrame:NSZeroRect]];
}
@end
The actual value is passed to the setter method, but just not held by the property I think, but why? Tried multiple properties, strong, readwrite atomic or nonatmoic but thats not helping.
What is the thing to get the NSCollectionView set up with bindings?
Thanks
Benjamin
_______________________________________________
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