これは数週間前から頭痛の種です - 誰かが助けてくれることを願っています. Titanium モバイルの 2.1.4 SDK を使用して、iOS 5.0 用のアプリを作成しています。私のアプリはデータベースからデータを取得し、ラベルとテーブルを使用してスクロール可能なビューに表示します。しばらくするとクラッシュすることに気付きました。インストルメントによると、scrollableView 内のビューは、ラベルやテーブルビューと共に、メモリから解放されることはありません。私は多くの commonJS を使用しており、私のコードは次のようになります (簡略化):
app.js から呼び出す ApplicationWindow モジュール
function ApplicationWindow(title) {
var self = Ti.UI.createWindow({
title:title,
backgroundColor:'white'
});
var button = Ti.UI.createButton({
height:44,
width:200,
title:L('openWindow'),
top:20
});
self.add(button);
var QuizWindow = require('/ui/common/QuizWindow');
button.addEventListener('click', function() {
//containingTab attribute must be set by parent tab group on
//the window for this work
qw = new QuizWindow({title: 'KCT', backgroundColor: 'white', navBarHidden: true, tabBarHidden: true});
self.containingTab.open(qw);
});
return self;
};
module.exports = ApplicationWindow;
次に、QuizWindow モジュールを呼び出します。
function QuizWindow(args){
var instance = Ti.UI.createWindow(args);
var QuestionView = require('/ui/common/QuestionView');
var db = Ti.Database.install("/kct.sqlite","kct");
var q = db.execute("SELECT * FROM questions");
var sv = Ti.UI.createScrollableView({
bottom: 40
});
while(q.isValidRow()){
var id = q.fieldByName("qid");
var question = q.fieldByName("q");
var set = q.fieldByName("set");
var info = q.fieldByName("info");
var v = new QuestionView(id,set,question,info);
sv.addView(v);
q.next();
}
q.close();
db.close();
var button = Ti.UI.createButton({
height:44,
width:200,
title:"Close",
bottom:10
});
button.addEventListener('click', function() {
instance.close({animation: true});
});
instance.add(sv);
instance.add(button);
return instance;
};
module.exports = QuizWindow;
これが QuestionView です。
function QuestionView (id,set,question,infolert) {
var qview = Ti.UI.createView({
top: 0,
width: 'auto',
height: 'auto',
backgroundColor: 'white',
questionSet: set,
questionID: id,
info: infolert,
isAnswered: false
});
var qLabel = gui.Header(question);
qLabel.top = 5;
qLabel.left = 10;
qLabel.right = 10;
qLabel.color = "#3B3B3B";
qLabel.font = {fontSize: gui.defaultFontSize+4, fontWeight: 'bold'};
var dcalc = (qLabel.text.length / 30) * ((gui.defaultFontSize+4)*1.2) + 5;
var answView = Ti.UI.createTableView({
backgroundColor: 'white',
top: dcalc,
_parent: qview
});
var changeheight = function(e) {
var lheight = e.source.rect.height;
if(lheight && lheight > 10) answView.top = lheight + 5;
return;
};
qLabel.addEventListener('postlayout', changeheight);
qview.add(qLabel);
qview.add(answView);
return qview;
}
module.exports = QuestionView;
もともと、データベースから回答のデータを取得し、それを tableView に入力するためのコードがいくつかありましたが、簡潔にするために削除しました。それがなくても、何も解放されません。私はここで本当に途方に暮れています。アドバイスをいただければ幸いです。