【问题标题】:Titanium - The contents of my TableViewRow colors are overridden when I click the rowTitanium - 当我单击行时,我的 TableViewRow 颜色的内容被覆盖
【发布时间】:2012-09-17 19:58:33
【问题描述】:

我正在开发 Titanium 并为 iOS 开发,我创建了一个 TableView,每行都有一个按钮,当您单击该行时,另一个按钮会添加到该行中,如果再次单击该按钮,则会删除每个控件有自己的行为和风格。我正在处理的问题是,当我单击该行时,按钮上的样式被覆盖,我的意思是,如果任何按钮具有特定的背景颜色,则所述颜色将被覆盖并替换为行的背景颜色,字体颜色也会发生这种情况。

这是该行在被点击之前的外观截图:

下一个是当我单击该行并添加另一个按钮时:

查看小灰色按钮背景颜色如何更改为与行背景颜色相同的颜色。当我单击该行使按钮消失并再次单击该行使其重新出现时,也会发生同样的情况:

这就是我定义行和按钮的方式:

function addToDo(title, priority, taskId){
    var that = {};

    var row = Ti.UI.createTableViewRow({
        height:80, 
        value : taskId,
        backgroundSelectedColor : 'transparent',
        selectedBackgroundColor : 'transparent',
        selectedColor : 'transparent',
        item_type : 'ROW'
    });

    that.currentPriority = priority;

    that.resolveColor = function(tmpPriority){
        switch(tmpPriority){

            case 0: backgroundColorPriority = "#da362a"; break;
            case 1: backgroundColorPriority = "#da6c2a"; break;
            case 2: backgroundColorPriority = "#da962a"; break;
            case 3: backgroundColorPriority = "#dacb2a"; break;             
        }
        return backgroundColorPriority;
    }

    var rowLayout = Ti.UI.createView({
        backgroundColor : 'transparent'
    });

    var checkbox = Ti.UI.createButton({
        top: 25,
        left: 5,
        width: 30,
        height: 30,
        borderColor: 'white',
        borderWidth: 2,
        borderRadius: 1,
        backgroundColor: '#b1b1b1',
        backgroundImage: 'NONE',
        item_type : 'CHECKBOX',
        value: false //value is a custom property in this case here.
    });

    row.add(checkbox);

    //Attach some simple on/off actions
    checkbox.on = function(item) {
        this.backgroundColor = '#62b425';
        item.backgroundColor = "#101010";
        this.value = true;
    };

    checkbox.off = function(item) {
        this.backgroundColor = '#b1b1b1';
        item.backgroundColor = that.resolveColor(item.currentPriority);
        this.value = false;
    };

    // Create a Label.
    var todoTitleLabel = Ti.UI.createLabel({
        text : title,
        color : 'white',
        font : {fontSize:11},
        left : 40,
        top : 35,
        textAlign : 'center'
    });

    // Add to the parent view.
    row.add(todoTitleLabel);

    // Create a Button.
    var deleteTask = Ti.UI.createButton({
        title : 'Borrar',
        height : 50,
        width : 100,
        top : 85,
        left : 110,
        item_type : 'DELETEBUTTON',
        style : Ti.UI.iPhone.SystemButtonStyle.PLAIN,
        color : '#000',
        backgroundSelectedColor : '#F7F8E0',
        selectedColor : '#F7F8E0',
        backgroundColor : '#F7F8E0'
    });

    // Add to the parent view.
    row.expand = function(){
        this.height=160;
        row.add(deleteTask);            
    };

    row.contract = function(){
        this.height=80;
        row.remove(deleteTask);

    };

    var backgroundColorPriority = that.resolveColor(that.currentPriority);      
    row.backgroundColor = backgroundColorPriority;
    that.currentRow = row;

    checkbox.container = that.currentRow;

    return that;
}

这就是我处理行上的点击事件的方式:

table.addEventListener('click', function(e){
    if(e.source.item_type == 'CHECKBOX'){
        if(false == e.source.value) {
            e.source.on(e.source.container);
        } else {
            e.source.off(e.source.container);   
        }
    }else if(e.source.item_type == 'DELETEBUTTON'){
        alert('delete button');
    }else if(e.source.item_type == 'ROW'){
        if(!borraState){
            Ti.API.info('IN ' + JSON.stringify(e));
            taskId = e.row.value;
            todoId = tasks[taskId].todoId;
            index = e.index;
            borraLayout.animate(borrarLayoutIn);
            e.source.expand();
            borraState = true;
        }else{
            Ti.API.info('OUT ' + JSON.stringify(e));
            borraLayout.animate(borrarLayoutOut);
            borraState = false;
            e.source.contract();
        }
    }
});

我不明白为什么单击该行时颜色会被覆盖,即使我在处理事件时尝试重新定义背景颜色,但无济于事。我做错了什么?

【问题讨论】:

    标签: events styles titanium tableview appcelerator


    【解决方案1】:

    我通过将下一个属性添加到我的 TableViewRow 解决了这个问题

    selectionStyle : Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE
    

    该属性使其在点击/按下/单击/等行时不会显示颜色或效果。

    【讨论】:

      【解决方案2】:

      注意:

      Titanium.UI.iPhone.TableViewCellSelectionStyle 已弃用

      改用 Titanium.UI.iOS.TableViewCellSelectionStyle

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-24
        • 1970-01-01
        • 1970-01-01
        • 2021-10-17
        • 2014-07-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多