NSCollectionView在ARC下发布了强大的属性

时间:2014-02-20 16:19:54

标签: objective-c cocoa automatic-ref-counting nszombie nscollectionview

我创建了NSCollectionView的子类,因为我想以编程方式实现它。没有什么特别的,除了今天我想激活选择。我正在使用ARC。

collectionView在我的文档中具有强大的属性。这很好,我可以用它做任何事情。今天我设置了setSelectable:YES也可以正常工作,Item被选中并突出显示。如果我试图拖动该项(意外)该程序崩溃。然后我打开仪器找到Zombie对象并且有它。在我的文档的initCollectionView方法中,collectionView是malloc'ed,但也在同一方法中dealloc'ed。为什么? 因为程序崩溃发送canDragItemsAtIndex调用并且说集合视图不再存在。

为什么会发生这种情况或我该怎么做呢?没有setSelectable:YES它不会崩溃尝试拖动一个Item(这应该是它应该做的)

好的,可能没有强引用了,但是当initCollectionView结束时我怎么能得到一个呢?

谢谢你们 本杰明

* EDC * initCollectionView的代码

-(void)initCollectionView {

UInt16 width  = 3000;



self.channelController = [[NSArrayController alloc] init];
[self.channelController setAutomaticallyRearrangesObjects:YES];
[self.channelController setAutomaticallyPreparesContent:YES];
[self.channelController bind:@"contentArray" toObject:self withKeyPath:@"channelArray" options:Nil];



self.collectionView = [[ChannelCollectionView alloc] initWithFrame:NSMakeRect(0, 0, width, self.splitview.frame.size.height)];
[self.collectionView setItemPrototype:[ChannelViewItemController new]];
[self.collectionView setMaxNumberOfRows:1];
[self.collectionView setMaxItemSize:NSMakeSize(110, 800)];
[self.collectionView setMinItemSize:NSMakeSize(110, 800)];
[self.collectionView setAutoresizingMask:(NSViewMinXMargin | NSViewWidthSizable | NSViewMaxXMargin | NSViewMinYMargin  | NSViewHeightSizable| NSViewMaxYMargin)];
[self.collectionView setAutoresizesSubviews:YES];
[self.collectionView bind:NSContentBinding toObject:self.channelController withKeyPath:@"arrangedObjects" options:nil];
[self.collectionView setSelectable:YES];


CollectionViewController *delegateController = [[CollectionViewController alloc] init];

[self.collectionView setDelegate:delegateController];


self.scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, self.splitview.frame.size.width-220, self.splitview.frame.size.height)];

[self.scrollView setHasVerticalScroller:YES];
[self.scrollView setHasHorizontalScroller:YES];
[self.scrollView setVerticalScrollElasticity:NSScrollElasticityNone];
[self.scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
//[self.scrollView setDrawsBackground:YES];
//[self.scrollView setBackgroundColor:[NSColor greenColor]];


[self.scrollView setAutoresizesSubviews:YES];
[self.scrollView setDocumentView:self.collectionView];


[self.splitview addSubview: self.scrollView];


}

0 个答案:

没有答案