NSCollectionViewItem 的项目出口的 NSView 子类绘制不一致
我到处寻找这个但没有运气。 我在我的项目中使用 NSCollectionView 并通过数组控制器绑定到核心数据。 为了使它看起来像我想要的那样,我使用新的drawRect方法对NSView进行了子类化,并将其与NSCollectionViewItem的视图出口连接起来。 一切正常,绑定也很好,但由于某种原因,它只会在集合视图中的第一个项目上执行自定义绘图。我猜这与 NSCollectionView 在创建新项目时复制笔尖有关。 首先是我的drawRect:方法:
@implementation CompanyItemView
-(void)drawRect:(NSRect)dirtyRect
{
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:[self frame]
xRadius:6.0f
yRadius:6.0f];
[[NSColor whiteColor] set];
[path fill];
[[NSColor darkGrayColor] set];
[path stroke];
}
@end
有什么想法吗?
I have searched everywhere for this one but have had no luck.
I am using an NSCollectionView in my project with bindings to Core Data via an Array Controller.
In order to make it look the way I want I have subclassed NSView with a new drawRect method and connected this with the view outlet of the NSCollectionViewItem.
It all works properly and the bindings are good but it will only perform the custom drawing on the first item in the collection view for some reason. I'm guessing it is to do with the fact that NSCollectionView copies the nibs when creating a new item.
Here is my drawRect: method firstly:
@implementation CompanyItemView
-(void)drawRect:(NSRect)dirtyRect
{
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:[self frame]
xRadius:6.0f
yRadius:6.0f];
[[NSColor whiteColor] set];
[path fill];
[[NSColor darkGrayColor] set];
[path stroke];
}
@end
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不完全确定,但我认为你需要实现 copyWithZone 方法
Not completely sure but i Think you need to implement copyWithZone method