We can create these files and write them to our local phone storage, but what about deleting them? In this recipe, we'll explain how to safely check for and delete files using the Ti.Filesystem.File
namespace.
In your app.js
file, before you create tab2
, add the following button code with an event listener. This will be our trash button and will call the delete
function on the currently selected image:
//create trash button var buttonTrash = Ti.UI.createButton({ width: Ti.UI.SIZE, height: Ti.UI.SIZE, right: 25, bottom: 25, title: 'Delete', zIndex: 2, visible: false }); //create event listener for trash button buttonTrash.addEventListener('click', function(e){ });
We add an extra line to our existing btnSaveCurrentPhoto
click event to make our trash button visible only after a photo has actually been saved to the disk:
btnSaveCurrentPhoto.addEventListener('click', function(e){ …. buttonTrash...