I have a modal window with a UI Picker it loads properly and closes properly the first time it pops up. The second time it runs there are 2 UI Pickers, the third time it runs there are 3 UI Pickers, etc... I am closing the modal properly and it is being created within an AddEventListener so I thought it would be destroyed properly, my partial code is here:
function DetailView() { var self = Ti.UI.createView({ backgroundColor: '#dddddd', layout: 'vertical' });
var tbl = Ti.UI.createTableView({
bottom: 70,
height: Ti.UI.FILL,
width: Ti.UI.FILL
});
self.add(tbl);
var data = [{title:"Row 1"},{title:"Row 2"}];
tbl.setData(data);
var btnEmail = Ti.UI.createButton({
title: 'Email',
top: 10,
height: Ti.UI.SIZE,
left: 10,
width: '45%'
});
btnEmail.addEventListener('click', function() {
Ti.App.addEventListener('contactSelected', function(e) {
// LOAD MODAL
var contactWin = require('ui/common/Recommend/contactModal');
contactModal = new contactWin(e.data);
});
});
return self; }; module.exports = DetailView;
contactModal.js function contactModal(data) {
var emailPicker = Ti.UI.createPicker({
selectionIndicator: true,
top: '40%',
useSpinner: true
});
emailPicker.add(data);
emailPicker.addEventListener('change', function(e) {
var emailAddress = e.source.getSelectedRow(0).emailVal;
modalWin.close();
var body = 'body';
// lib/mail Uses the Titanium.UI.createEmailDialog(); to send an email
var Mail = require('lib/Mail');
Mail.sendEmail(emailAddress, 'recomendation', body);
});
var modalWin = Ti.UI.createWindow({
title: 'Email Picker',
backgroundColor: 'transparent',
layout: 'vertical',
modal: true
});
modalWin.add(emailPicker);
modalWin.open();
}; module.exports = contactModal;
1 Answer
Accepted Answer
its because your Ti.App.addEventListener, this belongs to a global namespace and wont be removed automatically. Clicking n Times on btnEmail will add n Listeners and open n Times you window. Remove the EventListener on window close or use a different Approach.
Your Answer
Think you can help? Login to answer this question!