Skip to content

Instantly share code, notes, and snippets.

@minhnc
minhnc / app.js
Created May 3, 2012 23:14
Determine if File or Directory in iOS
function isDir(path) {
var file = Ti.Filesystem.getFile(path);
if ( !file.exists() ) {
return false;
}
var nativePath = file.nativePath;
Ti.API.info(nativePath);
@minhnc
minhnc / app.js
Created April 21, 2012 03:50
Navigation & TabGroup
var rootWindow = Titanium.UI.createWindow({backgroundColor : "white", title : "Login"});
var loginBtn = Ti.UI.createButton({title: 'Login', width: 100, height: 40});
rootWindow.add(loginBtn);
var nav = Titanium.UI.iPhone.createNavigationGroup({
window : rootWindow
});
var win = Titanium.UI.createWindow();
@minhnc
minhnc / app.js
Created April 18, 2012 23:35
Flexible Object Sort
var win = Ti.UI.createWindow();
var data = [];
for(var i = 0; i < 5; i++) {
data.push({title : 'Title ' + i, id : i.toString(), addr : 'Addr ' + i});
}
var table = Ti.UI.createTableView({
data : data,
_data : data
@minhnc
minhnc / app.link
Created April 16, 2012 14:35
Host Server in Mobile app
@minhnc
minhnc / app.js
Created April 15, 2012 14:47
ImageView with SVG
var win = Titanium.UI.createWindow({backgroundColor: 'white'});
var img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
var index = img.indexOf('base64,');
img = img.substring(index + 'base64,'.length);
Ti.API.info(img);
var imageView = Ti.UI.createImageView({
image: Ti.Utils.base64decode(img),
width: 100,
@minhnc
minhnc / app.js
Created April 15, 2012 08:31
Navigation Group
var rows = [];
for( var i = 0; i < 30; i++ ) {
var row = Ti.UI.createTableViewRow({
title: 'Row ' + i,
recordID: i
});
rows.push(row);
}
@minhnc
minhnc / app.js
Created April 15, 2012 00:44
Table with Index Entry
var win = Ti.UI.createWindow({
backgroundColor:'#fff'
});
 
// create table view data object
var data = [
{title:'Alan', hasChild:true, header:'A'},
{title:'Alice', hasDetail:true},
{title:'Alexander'},
{title:'Amos'},
@minhnc
minhnc / link
Created April 8, 2012 08:05
Interact b/t Remote Webview & Ti
@minhnc
minhnc / app.js
Created April 8, 2012 00:21
Remove All EventListeners
var win = Ti.UI.createWindow();
win.open();
/// <<< Register & UnRegister Event Listeners
/**
* params: {event: 'event', callback: eventCallback}
*/
function registerEventListener(obj, params) {
if ( typeof obj._eventListeners == 'undefined' ) {
@minhnc
minhnc / app.js
Created March 17, 2012 15:30
TableView - Custom SearchBar: Prefix Search, Customize No Result
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var searchbar = Ti.UI.createSearchBar({ top: 0, height: 43, showCancel: false });
win.add(searchbar);
// Function to dump data
function dumpData() {
var data = [];
for(var i = 0; i < 20; i ++) {
data.push({title: Math.random().toString(36).substring(5)});
}