带钛的IOS7风格内联选择器

时间:2014-06-05 21:06:09

标签: ios7 titanium inline picker

有没有人在Titanium中实现IOS7样式的内联选择器?我会感谢任何提示或演示。

例如在日历中:http://i.stack.imgur.com/hUDZK.png

这是我目前的代码:

var HintTextArea = require('hinttextarea');

var self = Ti.UI.createWindow({
    backButtonTitle: '',    
    title: L('addwish_title'),  
    backgroundColor: 'white',
    layout: 'vertical',
});

var title = Ti.UI.createTextField({
    hintText: L('addwish_title'),
    borderStyle: Ti.UI.INPUT_BORDERSTYLE_NONE,
    color: 'black',
    top: 10, bottom: 10, left: 40,
    width: 270, 
    height: Ti.UI.SIZE,
    suppressReturn: true            
});
var rowTitle = Ti.UI.createTableViewRow({touchEnabled: false}); 
rowTitle.add(title);

var category = Ti.UI.createLabel({
    text: L('addwish_category'),
    touchEnabled: false,
    color: 'black',
    top: 10, bottom: 10, left: 40,
    width: 270, 
    height: Ti.UI.SIZE  
}); 
var rowCategory = Ti.UI.createTableViewRow({}); 
rowCategory.add(category);

var categoryPicker = Ti.UI.createPicker({
    //visible: false,
    selectionIndicator: true,
    //height: 0
});
var data = [];
data[0]=Ti.UI.createPickerRow({title:'Bananas'});
data[1]=Ti.UI.createPickerRow({title:'Strawberries'});
data[2]=Ti.UI.createPickerRow({title:'Mangos'});
data[3]=Ti.UI.createPickerRow({title:'Grapes'});
data[4]=Ti.UI.createPickerRow({title:'Bananas'});
data[5]=Ti.UI.createPickerRow({title:'Strawberries'});
data[6]=Ti.UI.createPickerRow({title:'Mangos'});
data[7]=Ti.UI.createPickerRow({title:'Grapes'});

categoryPicker.add(data);   

categoryPicker.setSelectedRow(0, 3);

var rowPicker = Ti.UI.createTableViewRow({touchEnabled: false});    
rowPicker.add(categoryPicker);  

var description = HintTextArea.createTextArea({
    color: 'black',
    font: {fontSize: 16},
    top: 10, left: 39,
    height: 180,
    width: 272,
    suppressReturn: true
}); 
var rowDescription = Ti.UI.createTableViewRow({touchEnabled: false});   
rowDescription.add(description);    

var footerView = Ti.UI.createView({
    height : Ti.UI.SIZE
});

var addWishButton = Ti.UI.createButton({
    title: L('addwish_add_button'),
    height: 20,
    top: 10,
    bottom: 5
});
footerView.add(addWishButton);  

// now add the complete tableview form
var tableView = Ti.UI.createTableView({
  data: [rowTitle, rowCategory, rowDescription],
  footerView : footerView,
  allowsSelection: false
});
self.add(tableView);


// *** EVENTS

category.addEventListener('click', function(e) {
    Ti.API.debug('category event');
    // check if the picker is already visible
    tableView.insertRowAfter(1, rowPicker);

});

self.open();

1 个答案:

答案 0 :(得分:0)

问题是您将事件侦听器添加到Label视图,该视图的属性touchEnabled设置为false。将其更改为:

var category = Ti.UI.createLabel({
    text: L('addwish_category'),
    color: 'black',
    top: 10, bottom: 10, left: 40,
    width: 270,
    height: Ti.UI.SIZE
});

以及事件监听器:

// *** EVENTS
var pickerEnabled = false;
category.addEventListener('singletap', function(e) {
    Ti.API.debug('category event');
    // check if the picker is already visible
    if (pickerEnabled) {
        tableView.deleteRow(rowPicker);
        pickerEnabled = false;
    } else {
        tableView.insertRowAfter(1, rowPicker);
        pickerEnabled = true;
    }
});

TableView中的click事件存在问题,但singletap工作正常。

此外,我添加了简单的if语句,这将阻止向表中添加第二个选择器。