Created
September 28, 2013 05:13
-
-
Save yagitoshiro/6738602 to your computer and use it in GitHub Desktop.
ページ遷移しながらデータを次のWindowに引き渡し、ついでに自分を消して戻れなくするパターン。実際には、Question.jsとAnswer.jsがほぼ同じ内容なので、外観に関わる部分を外に出してrequireして、共通化する方がいいと思います。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//試験を開始するWindowにて | |
var Window, window; | |
Window = require('ui/handheld/Question'); | |
window = new Window(1); | |
window.containingTab = self.containingTab; | |
self.containingTab.open(window); | |
//ui/handheld/Question.js | |
function Question(id){ | |
var self, button; | |
self = Ti.UI.createWindow({ | |
backgroundColor: 'White', | |
title: '第' + id + '問' | |
}); | |
//渡されたidで問題のデータを取得、問題を表示する | |
button = Ti.UI.createButton({ | |
title: '回答を見る', | |
width: Ti.UI.SIZE, | |
height: Ti.UI.SIZE | |
}); | |
self.add(button); | |
button.addEventListener('click', function(){ | |
var Window, window; | |
Window = require('ui/handheld/Answer'); | |
window = new Window(id); | |
window.containingTab = self.containingTab; | |
self.containingTab.open(window); | |
window.addEventListener('open', function(){ | |
self.close(); | |
}); | |
}); | |
return self; | |
} | |
module.exports = Question; | |
//ui/handheld/Answer.js | |
function Answer(id){ | |
var self, button; | |
self = Ti.UI.createWindow({ | |
backgroundColor: 'White', | |
title: '第' + id + '問の回答' | |
}); | |
//渡されたidで問題のデータを取得、回答を表示する | |
button = Ti.UI.createButton({ | |
title: '次の問題', | |
width: Ti.UI.SIZE, | |
height: Ti.UI.SIZE | |
}); | |
self.add(button); | |
button.addEventListener('click', function(){ | |
var Window, window; | |
Window = require('ui/handheld/Question'); | |
window = new Window(id += 1); | |
window.containingTab = self.containingTab; | |
self.containingTab.open(window); | |
window.addEventListener('open', function(){ | |
self.close(); | |
}); | |
}); | |
return self; | |
} | |
module.exports = Answer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment