简体   繁体   中英

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.

Ti Mobile SDK: 1.7.0RC1 and 1.6.2 iOS SDK: 4.2 Android API: (Google APIs) 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.

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.

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.

Does anyone know if the iOS SDK would somehow prohibit sub-classing it's "vanilla" UI components?

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. Try renaming the function -- 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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