调整 NSCollectionViewItem 视图的大小
如何以编程方式设置 NSCollectionViewItem 视图的大小?
我尝试在 NSCollectionView 子类中执行此操作:
@implementation CustomCollectionView
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
NSCollectionViewItem *newitem = [[self itemPrototype] copy];
[newitem setRepresentedObject:object];
NSView *itemview = [newitem view];
[itemView setFrame:NSMakeRect([itemView frame].origin.x, [itemView frame].origin.y, [itemView frame].size.width, 500)];
return newitem;
}
@end
但是此代码没有效果。我尝试对用于 NSCollectionViewItem 的 NSView 进行子类化,并将 setFrame: 添加到 initWithCoder 方法中,但是当我这样做时,我遇到了 EXC BAD ACCESS 崩溃。
How do I programatically set the size of a view of an NSCollectionViewItem?
I tried doing this in an NSCollectionView subclass:
@implementation CustomCollectionView
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
NSCollectionViewItem *newitem = [[self itemPrototype] copy];
[newitem setRepresentedObject:object];
NSView *itemview = [newitem view];
[itemView setFrame:NSMakeRect([itemView frame].origin.x, [itemView frame].origin.y, [itemView frame].size.width, 500)];
return newitem;
}
@end
However this code has no effect. I tried subclassing my NSView that I use for the NSCollectionViewItem, and adding setFrame: to the initWithCoder method, but I get an EXC BAD ACCESS crash when I do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看 Steven Degutis 提供的这个开源 NSCollectionView 替代方案,巧合的是,我认为它今天刚刚发布到 GitHub(我今天通过 Twitter 注意到了它):
http://github.com/sdegutis/SDListView
看起来它允许您拥有不同高度的项目。
You might checkout this open source NSCollectionView alternative from Steven Degutis which, coincidentally I think was just posted to GitHub today (I noticed it today via Twitter):
http://github.com/sdegutis/SDListView
Looks like it allows you to have items with different heights.