[英]Property Grid for Cocoa
I didn't find anything similar to .NET PropertyGrid class in Cocoa, so I started to write my own version. 我在Cocoa中没有找到与.NET PropertyGrid类相似的东西,因此我开始编写自己的版本。 I use information from runtime to get properties of object: 我使用来自运行时的信息来获取对象的属性:
Class reflectedClass = [reflectedObject class];
uint propertyCount = 0U;
objc_property_t *properties = class_copyPropertyList(reflectedClass,
&propertyCount);
And this for getting/setting values in NSTableView: 这是为了获取/设置NSTableView中的值:
- (NSString *)propertyNameAtIndex:(int)index
{
return (NSString *)[cachedPropertyNames objectAtIndex:index];
}
- (id)propertyValueAtIndex:(int)index
{
return [reflectedObject valueForKey:[self propertyNameAtIndex:index]];
}
- (void)setPropertyValue:(id)value atIndex:(int)index
{
[reflectedObject setValue:value forKey:[self propertyNameAtIndex:index]];
}
For syncing updates with reflectedObject
is used basic KVO: 为了使更新与reflectedObject
同步,使用了基本的KVO:
[reflectedObject addObserver:self
forKeyPath:propertyName
options:NSKeyValueObservingOptionOld |
NSKeyValueObservingOptionNew
context:NULL];
This solution works, but I have two problems that I need to fix: 此解决方案有效,但是我需要解决两个问题:
I am still beginner in Cocoa so sorry if I am asking for something really basic. 我仍然是可可的初学者,如果我要的是真正的基本知识,对不起。
UPDATE: I need something like this (picture from Xcode->Get Info->Build): 更新:我需要这样的东西(图片来自Xcode-> Get Info-> Build):
PropertyGridCocoa http://www.adorior.cz/Images/PropertyGridCocoa.png PropertyGridCocoa http://www.adorior.cz/Images/PropertyGridCocoa.png
Cocoa has no such view built in to the framework. 可可在框架中没有内置这种观点。 If no-one else has created one and released it as open source, you will need to create one from the ground up. 如果没有其他人创建了一个并将其发布为开源,则需要从头开始创建一个。
It's probably easier to hand-craft a UI that matches the underlying model. 手工制作与基础模型匹配的UI可能更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.