Titaniumで「[ERROR] Adding an event listener to a proxy that isn't already in the context」が出る一例と対処法
久しぶりに Titanium Mobile でつくったアプリをリファクタリングしようと、SDKを一気に最新の2.0にしてビルドしてみたら、Consoleに
[ERROR] Adding an event listener to a proxy that isn't already in the context [ERROR] Adding an event listener to a proxy that isn't already in the context [ERROR] Adding an event listener to a proxy that isn't already in the context [ERROR] Adding an event listener to a proxy that isn't already in the context
というエラーがたくさん。どこでエラーが出てるのかコードを追っていくと、 Ti.UI.createButton() をしている箇所で発生していることが判明。
var searchButton = Ti.UI.createButton({
image: '/images/search-b.png',
backgroundGradient: headerButtonGradient,
borderWidth: 1,
borderColor: '#333',
borderRadius: 8,
style: Ti.UI.iPhone.SystemButtonStyle.PLAIN,
width: app.config.SEARCH_BUTTON_WIDTH,
height:32,
top:6,
right: app.config.SEARCH_BUTTON_RIGHT
});
どこも間違ってる所はなさそうなのに・・・と、オプションを1個ずつ調べてみると「backgroundGradient」をコメントアウトしたらエラーが消えました。
そこでこれらを手がかりに解決策を調べてみると、公式のフォーラムに以下の投稿が。
これによると、
A quick and dirty fix for this issue is to set the backgroundGradient AFTER you have created the button and added it to a view.
つまり「createButtonをした後に、backgroundGradientをセットしろ」と。
var searchButton = Ti.UI.createButton({
image: '/images/search-b.png',
borderWidth: 1,
borderColor: '#333',
borderRadius: 8,
style: Ti.UI.iPhone.SystemButtonStyle.PLAIN,
width: app.config.SEARCH_BUTTON_WIDTH,
height:32,
top:6,
right: app.config.SEARCH_BUTTON_RIGHT
});
searchButton.setBackgroundGradient(headerButtonGradient);
こういうことみたいです。確かにエラーが消えてくれました。
コメントを残す