C-structs、NSObjects、float、int、double、,
首先:这是一个问题,很抱歉,但我希望有人能帮助我 我正在iPhone上制作UIML渲染器。UIML是一种描述接口的语言。 我想在iPhone上呈现XML并显示界面 为了更好地通知您,我首先解释一下我在做什么:C-structs、NSObjects、float、int、double、,,struct,floating-point,return-value,nsobject,return-type,Struct,Floating Point,Return Value,Nsobject,Return Type,首先:这是一个问题,很抱歉,但我希望有人能帮助我 我正在iPhone上制作UIML渲染器。UIML是一种描述接口的语言。 我想在iPhone上呈现XML并显示界面 为了更好地通知您,我首先解释一下我在做什么: <?xml version="1.0"?> <uiml> <interface> <structure> <part id="hoofdView" class="ViewController"
<?xml version="1.0"?>
<uiml>
<interface>
<structure>
<part id="hoofdView" class="ViewController">
<part id="viewVoorHoofdview" class="View">
<part id="label1" class="Label"/>
</part>
</part>
</structure>
<style>
<property part-name="label1" name="text">Dit is een label</property>
<property part-name="label1" name="position">50,50,100,150</property>
</style>
</interface>
<peers>
<presentation base="cocoa.uiml"/>
</peers>
</uiml>
然后我必须将这些属性应用到createdObject。
我们有两个属性:文本和位置
我们在词汇表中查找它们,让我们以位置为例
<d-property id="position" maps-type="setMethod" maps-to="setFrame:">
<d-param type="CGRect"/>
</d-property>
因为CGRect不是NSObject*
例如,当我必须将浮点传递给UISlider时,也会出现同样的问题
<d-property id="minimumValue" maps-type="setMethod" maps-to="setMinimumValue:">
<d-param type="float"/>
</d-property>
我调用它的方法是非常抽象的,必须是抽象的,因为我们希望在不添加代码的情况下扩展UIML文档词汇表。
这是从以下位置调用的方法:
-(void)invokeMethod:(Uproperty*)property dProperty:(DProperty *)dProperty guiElement:(NSObject *)object {
//Prepare the invocation
SEL selector = NSSelectorFromString(dProperty.m_mapsTo);
NSMethodSignature * signature = [ [object class] instanceMethodSignatureForSelector:selector];
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:signature];
//target, selector, arguments
[invocation setTarget:object];
[invocation setSelector:selector];
//Convert the argument to the correct type with the type decoder
DParam *dParam = [dProperty.m_dParams lastObject];
NSObject * argument = [m_decoder convert:property.m_data parameterType:dParam.m_type]; //only 1 d-param
//Then we can set the argument
[invocation setArgument:&argument atIndex:2]; //2 is the first parameter (0 = self, 1 = _cmd)
//Invoke the method
[invocation invoke];
}
很抱歉这个难题,但我希望有人能帮助我 您可能希望为所有不是NSObject子类的类型构建包装器类。
例如,NSNumber作为浮点数、整数等的对象包装器。是否有特定的问题?因为我看不到。
<d-property id="position" maps-type="setMethod" maps-to="setFrame:">
<d-param type="CGRect"/>
</d-property>
<property part-name="label1" name="position">50,50,100,150</property>
-(NSObject*)convert:(NSString*)stringToConvert;
<d-property id="minimumValue" maps-type="setMethod" maps-to="setMinimumValue:">
<d-param type="float"/>
</d-property>
-(NSObject *)convert:(NSString *)data parameterType:(NSString *)paramType {
NSObject * result;
if ( [paramType isEqualToString:@"NSString*"] ) {
result = data;
} else if ([paramType isEqualToString:@"float"]) {
//HOW TO DO THIS?
} else if ([paramType isEqualToString:@"CGRect"]) {
//HOW TO DO THIS?
} else {
NSLog(@"TypeDecoder: No decoding method found for the given parameter Type: %@", paramType);
}
return result;
}
-(void)invokeMethod:(Uproperty*)property dProperty:(DProperty *)dProperty guiElement:(NSObject *)object {
//Prepare the invocation
SEL selector = NSSelectorFromString(dProperty.m_mapsTo);
NSMethodSignature * signature = [ [object class] instanceMethodSignatureForSelector:selector];
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:signature];
//target, selector, arguments
[invocation setTarget:object];
[invocation setSelector:selector];
//Convert the argument to the correct type with the type decoder
DParam *dParam = [dProperty.m_dParams lastObject];
NSObject * argument = [m_decoder convert:property.m_data parameterType:dParam.m_type]; //only 1 d-param
//Then we can set the argument
[invocation setArgument:&argument atIndex:2]; //2 is the first parameter (0 = self, 1 = _cmd)
//Invoke the method
[invocation invoke];
}