0
我已经切换到tableview的行。当用户点击或更改开关时,我想要切换开关的值。我已经在桌面视图上写了点击事件,它在android中正常工作,但在ios中它没有给开关值。在钛的ios中tableview的行获取开关ID和值
以下是我的代码。
for (var i = 0; stateList.length; i++) {
var tblRow = Ti.UI.createTableViewRow({
height : Ti.UI.SIZE,
title : stateList[i].state_name,
layout : 'vertical',
switch_id : stateList[i].state_id,
selectedBackgroundColor : Alloy.CFG.colors.white,
});
var mainView = Ti.UI.createView({
top : 20,
height : Ti.UI.SIZE,
width : Ti.UI.FILL,
backgroundColor : '#fff'
});
tblRow.add(mainView);
var rowLbl = Ti.UI.createLabel({
text : stateList[i].state_name,
textAlign : 'left',
left : 15,
right : 40,
color : Alloy.CFG.colors.color_333399,
font : {
fontSize : Alloy.CFG.fonts.f_12,
fontFamily : Alloy.CFG.font_family.calibri,
fontWeight : Alloy.CFG.font_weight.bold
}
});
stateSwitch = Ti.UI.createSwitch({
right : 10,
value : stateList[i].enable_disable,
});
mainView.add(rowLbl);
mainView.add(stateSwitch);
var bottom_view = Ti.UI.createView({
top : 20,
height : 1,
width : Ti.UI.FILL,
backgroundColor : Alloy.CFG.colors.color_cccccc
});
tblRow.add(bottom_view);
$.tbl_sendformState.insertRowAfter(1, tblRow);
}
在点击表格视图时,我正在提取开关ID和值,如下所示。
$.tbl_sendformState.addEventListener('click', function(e) {
Ti.API.info('e = ' + JSON.stringify(e));
var switch_id = e.row.switch_id;
var switch_value = e.source.value;
Ti.API.info('switch value after clicked stringify === ' + JSON.stringify(switch_value));
if (switch_value == true) {
if (switch_data.indexOf(switch_id) === -1) {
switch_data.push(switch_id);
}
Ti.API.info('switch clicked stringify === ' + JSON.stringify(switch_data));
} else {
if (switch_data.indexOf(switch_id) != -1) {
var i = switch_data.indexOf(switch_id);
switch_data.splice(i, 1);
}
Ti.API.info('switch does not clicked stringify === ' + JSON.stringify(switch_data));
}
});
function openDone(e) {
Alloy.Globals.loading.show(L("loadingmsg"), false);
var switch_value = JSON.stringify(switch_data);
Ti.API.info('switch_value == ' + switch_value);
Alloy.Globals.loading.hide();
}
和XML为表视图是
<Alloy>
<Window id="filter_s">
<TableView id="tbl_sendformState">
<TableViewRow backgroundColor="#fff" height="0" width="Titanium.UI.FILL"/>
<TableViewRow backgroundColor="#fff" height="0" width="Titanium.UI.FILL"/>
<TableViewRow height="100">
<Label id="bottom_lbl" color="Alloy.CFG.colors.color_333399" bottom="10"/>
</TableViewRow>
</TableView>
<View id="bottom_view">
<View id="view_clearAll" onClick="openClearAll">
<Label id="lbl_clearAll"/>
</View>
<View id="view_done" onClick="openDone">
<Button id="btn_done"/>
</View>
</View>
</Window>
</Alloy>
这是Android,但在IOS做工精细交换机ID不switch_data阵列得到推。
请有人帮助我是新的钛。
在此先感谢。