Skip to content

Instantly share code, notes, and snippets.

@onori
Created June 26, 2013 12:58
Show Gist options
  • Select an option

  • Save onori/5867170 to your computer and use it in GitHub Desktop.

Select an option

Save onori/5867170 to your computer and use it in GitHub Desktop.
Titanium
/**rowに突っ込んだオブジェクトをコールバックイベントで取得する方法**/
var lOnSelected = Ti.UI.createLabel({
width:100,
height:50,
left:495,
textAlign:'center',
opacity:0.5,
text:'選択'
});
var row = Ti.UI.createTableViewRow({
className:"NomalCell",
selectionStyle: Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE,
height:100,
});
//rowに適当な名前のプロパティをぶら下げて、オブジェクトを格納//
row.onSelected = lOnSelected;
//リスナで呼び出す時//
table.addEventListerner('click',function(e){
alert(e.rowData.onSelected.text) // -> 「選択」が取得できる
});
/**tableViewのhasCheckを単一選択にする**/
var lastRowClicked; // -> 最後にクリックされたrowを格納する変数
tableView.addEventListerner('click',function(e){
//クリックされたrow以外のhasCheckをfalseにする
if (lastRowClicked && lastRowClicked !== e.row) {
lastRowClicked.hasCheck = false;
}
//クリックしたrowのhasCheckをtrueにする
e.row.hasCheck = !e.row.hasCheck;
//同じrowをクリックした際はhasCheckを外す
if(lastRowClicked == e.row){
lastRowClicked.hasCheck = false;
}
//hasCheckが有効になったrowをlastRowClickedに格納
if(e.row.hasCheck){
lastRowClicked = e.row;
}
else{
lastRowClicked = undefined;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment