有一种方法在NSCollectionView中有不同的视图? [英] Is there a way to have varying views in an NSCollectionView?

查看:158
本文介绍了有一种方法在NSCollectionView中有不同的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要类似于iWork具有页面的模板选择屏幕的类似选项,您可以选择不同的模板,每个视图包含不同的信息和差异大小等。

I am wanting something similar to how iWork has the template selection screen for Pages when you can select different templates, and each view contains different info has difference sizes etc.

我已经尝试子类化NSCollectionView并确定使用newItemForRepresentedObject方法显示的视图(而不是使用itemPrototype视图Interface Builder),但它由于某种原因没有正确定位视图,并且不显示正确的视图数量对于存在的项目数。这里是我的代码。我希望有人可以有更好的方法来做到这一点,或者是如何做到这一点的一个例子。

I have tried subclassing NSCollectionView and determining which view to display using the newItemForRepresentedObject method (as opposed to using itemPrototype view Interface Builder), but it for some reason doesn't position the views correctly, and it does not show the correct number of views for the number of items present. Here is my code. I was hoping someone may have a better way to do this, or an example of how this is done.

personView和companyView是子类NSCollectionView中的属性,即IBOutlets到IB中的视图。

personView and companyView are properties in the subclassed NSCollectionView, that are IBOutlets to views in IB.

-(NSCollectionViewItem *)newItemForRepresentedObject:(id)object{
NSCollectionViewItem *collectionViewItem = [[NSCollectionViewItem alloc] init];

 [collectionViewItem setRepresentedObject:object];

 if([[object valueForKey:@"company"] boolValue] == YES){
     NSView *view = [companyView retain];
     [collectionViewItem setView:companyView];
 }else{
     [collectionViewItem setView:personalView];
 }

return collectionViewItem;

}

推荐答案

(甚至似乎不可能使一个NSCollectionView具有不同大小的项目视图;每个大小将需要是一个主大小的多个或整数除数,你需要做大量您确定要提出正确的问题吗?)

(It doesn't even seem possible to make an NSCollectionView with differently-sized item views; each size would need to be a multiple or integer divisor of some "main" size, and you'd need to do massive item-checking and -reordering to be sure it's even possible to render them in a grid. Are you sure you're asking the right question?)

此外,我还可以在iWork中看到这样的东西:它的模板选择器中的所有视图都是一样的。 (虽然他们的NSImageView subviews 有不同的大小。)我建议如果可能使用相同的视图,并适当地更改其子视图。很容易,例如,绑定文本字段的隐藏属性或更改图像视图的宽度。你不能创建一个适用于这两个类的视图,根据所表示的对象适当地改变它自己吗?

Also, I don't see anything like this in iWork: all the views in its template chooser are the same. (Though their NSImageView subviews are of different sizes.) I'd recommend if at all possible using the same view and changing its subviews appropriately. It's easy to, for example, bind text fields' "hidden" property or change the width of an image view. Can't you make a single view that works for both classes, changing itself appropriately depending on the represented object?

这篇关于有一种方法在NSCollectionView中有不同的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆