简体   繁体   English

扩展Titanium对象在iOS上不起作用

[英]Extending Titanium Objects Doesn't Work on iOS

I'm wondering if anyone can explain why the extension of titanium view proxies doesn't work on iOS, but works perfectly fine on the Android platform. 我想知道是否有人可以解释为什么Titan View代理的扩展在iOS上不起作用,而在Android平台上却可以正常工作。

Ti Mobile SDK: 1.7.0RC1 and 1.6.2 iOS SDK: 4.2 Android API: (Google APIs) 2.2 Ti Mobile SDK:1.7.0RC1和1.6.2 iOS SDK:4.2 Android API:(Google API)2.2

This is a very simple use case: 这是一个非常简单的用例:

var useCaseView = Ti.UI.createView({
layout: 'vertical',
right:0,
left:0, 
top:0,
height:200,
backgroundColor:'#fff'
});



var outputSwitch = Ti.UI.createSwitch({ 
value: true
}); 



outputSwitch.setTopValue = function(newValue) {
Ti.API.info('setTop' + newValue);
outputSwitch.top = newValue; 
};



outputSwitch.setTopValue(50);



useCaseView.add(outputSwitch);

What I'm trying to accomplish is adding a method to the switch's view proxy (setTopValue, in this case) and call it after the fact. 我要完成的工作是向交换机的视图代理(在本例中为setTopValue)添加一个方法,然后在事后调用它。

This works fine on Android, but on iOS the Ti.API.info call doesn't even get hit, indicating that it simply ignores that method. 这在Android上运行良好,但是在iOS上,Ti.API.info调用甚至都没有被点击,表明它只是忽略了该方法。

Although this example was brief, what I'm really trying to do is "sub-class" out-of-the-box Titanium UI components, and add some common methods for them to share, to cut down on repeated code. 尽管这个例子很简短,但我真正想做的是开箱即​​用的“子类” Titanium UI组件,并添加一些共享的通用方法,以减少重复的代码。

Does anyone know if the iOS SDK would somehow prohibit sub-classing it's "vanilla" UI components? 有谁知道iOS SDK是否会以某种方式禁止对其“原始” UI组件进行子类化?

We've received an answer (or rather a workaround) elsewhere: 我们在其他地方收到了答案(或更确切地说,解决方法):

i have found that naming functions with a prefix of 'get' or 'set' cause problems. 我发现以“ get”或“ set”为前缀的命名功能会引起问题。 Try renaming the function -- Aaron Saunders 尝试重命名功能-Aaron Saunders

Sure enough, renaming the function causes this code to work as expected. 果然,重命名该函数会使此代码按预期工作。

http://developer.appcelerator.com/question/121114/extending-objects-not-working-on-iphone http://developer.appcelerator.com/question/121114/extending-objects-not-working-on-iphone

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM