NSCollectionView借鉴了什么
题
我想设置一个 NSCollectionView
(我已经做到了这一成功在过去,但是由于某种原因它没这个时间)。
我有一个模式类称为"TestModel",它有一个 NSString
酒店刚刚返回string(只是用于测试目的,现在).然后,我有一个 NSMutableArray
财产宣言》在我的主要应用程序委托类,并向该阵列的中添加实例 TestModel
对象。
然后,我有一系列控制器,其内容列定的程序委托的 NSMutableArray
.我可以确认,一切都在这里是工作的罚款;NSLogging:
[[[arrayController arrangedObjects] objectAtIndex:0] teststring]
运行良好。
然后,我们所有适当的绑定的集合认定,(itemPrototype和内容),并为收藏图项目(图)。然后,我有一个文本领域集合中的项目认定的收藏图 Item.representedObject.teststring
.但是没有显示在收集查看当我开始的程序,只是一张空白的画面。我是什么丢失?
更新:这里是代码,我在使用(请求由威尔希普利):
// App delegate class
@interface AppController : NSObject {
NSMutableArray *objectArray;
}
@property (readwrite, retain) NSMutableArray *objectArray;
@end
@implementation AppController
@synthesize objectArray;
- (id)init
{
if (self = [super init]) {
objectArray = [[NSMutableArray alloc] init];
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
TestModel *test = [[[TestModel alloc] initWithString:@"somerandomstring"] autorelease];
if (test) [objectArray addObject:test];
}
@end
// The model class (TestModel)
@interface TestModel : NSObject {
NSString *teststring;
}
@property (readwrite, retain) NSString *teststring;
- (id)initWithString:(NSString*)customString;
@end
@implementation TestModel
@synthesize teststring;
- (id)initWithString:(NSString*)customString
{
[self setTeststring:customString];
}
- (void)dealloc
{
[teststring release];
}
@end
然后像我说的内容列的阵控制器是受到此"objectArray",内容NSCollectionView定阵控制器。arrangedObjects.我可以验证的阵控制器具有的对象,在通过NSLogging[arrayController arrangedObjects],并返回正确的对象。它只是没有显示在NSCollectionView.
更新2:如果我记录[collectionView内容]我得到什么:
2009-10-21 08:02:42.385 CollViewTest[743:a0f] (
)
问题可能是存在的。
更新3:要求这里是模式的项目:
http://www.mediafire.com/?mjgdzgjjfzw
它是一个菜单的应用程序,所以它没有窗口。当你建立和运行的程序,你会看到一个菜单项说,"试验",这将打开看法,即包含NSCollectionView.
感谢
解决方案
问题是,你不能正确地使用KVC.有两件事你可以做。
方法1:简单但不是那么优雅
- 使用下列代码添加反对阵
[[自mutableArrayValueForKey:@"objectArray"]addObject:试验];
这不是那么优雅,你必须指定该变量使用的字符串的价值,所以你不会得到编译器的警告时拼写不正确。
方法2:产生的韩国国际志愿者组织的方法所需要的阵列"objectArray".
- 选择酒店在你的口宣言》
- 选择脚本(脚本中的图标菜单)>码>的地方 访问decls上的剪贴板
- 糊的声明 适当的位置在你的口文件
- 选择脚本>码>的地方 访问定义上的剪贴板
- 糊的定义 适当的位置,在你执行情况的文件
然后可以使用的方法,看起来像
[self insertObject:test inObjectArrayAtIndex:0];