没有调用回收垃圾按钮

时间:2016-02-14 13:14:41

标签: ios button titanium titanium-alloy

我正在使用钛合金开发我的第一个应用程序。对于iOS,我使用原生iOS垃圾按钮,使用systemButton="TRASH"。对于该按钮,我还有一个onClick处理程序onClick="deleteReckon"。但是,单击“删除”按钮时不会调用deleteReckon方法。

这是" reckonDetails.xml"适用于iOS的视图(因此,包含在"视图"目录中的" ios"目录中):

<Alloy>
    <Window class="container">

        <!-- Make a toolbar for delete and info buttons -->
        <Toolbar platform="ios" bottom="0" borderTop="true" borderBottom="false">

                <!-- The Items tag sets the Toolbar.items property. -->
                <Items>
                    <Button id="info" systemButton="INFO_LIGHT" />
                    <FlexSpace/>
                    <Button id="del" onClick="deleteReckon" systemButton="TRASH" />
                </Items>

       </Toolbar>

        <!-- We will display all reckon detail, date, total, ... -->
     <View layout='vertical'>
          <Label id="dateLabel"></Label>
          <!-- ... OTHER LABELS ... -->
     </View>
   </Window>
</Alloy>

这是&#34; reckonDetails.js&#34;控制器:

var args = arguments[0] || {};

// Fill in all labels of this view
$.dateLabel.text = "Date: " + args.date || 'Unknown Date';
// ...

function deleteReckon() {
    console.log("deleteReckon called"); // Is never displayed

    // Delete the selected reckon (this element of the collection)
    var selectedReckon = args.selected_reckon;
    selectedReckon.destroy(); 

    // Go back to the index page
    var args = {};
    var indexView = Alloy.createController("index", args).getView();
    indexView.open();
}

我在其中放了一个console.log(...);语句来检查函数是否被调用,但它不是..

最后这是我的&#34; reckonDetails.tss&#34;风格(不确定这是否与问题相关?):

".container[platform=ios]" : { 
   backgroundColor: 'white' 
},

"Label": {
    font: {
        fontSize: '20'
    },
    left: '10'
},

"#dateLabel": {
    font: {
        fontSize: '30'
    },
    left: '10'
}

1 个答案:

答案 0 :(得分:0)

我在Titanium Alloy和Classic项目上测试了iOS系统TRASH按钮,它对我来说很好用。请查看下面的代码,

    var win = Ti.UI.createWindow({
    title : 'Window',
    backgroundColor: '#white'
});

var trash = Titanium.UI.createButton({
    systemButton: Titanium.UI.iPhone.SystemButton.TRASH,
});

flexSpace = Titanium.UI.createButton({
    systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});

var toolbar = Titanium.UI.iOS.createToolbar({
    items:[trash, flexSpace],
    bottom:0,
    borderTop:true,
    borderBottom:false
}); 
win.add(toolbar);

trash.addEventListener('click', function(){
    console.log("Treash called");
});

win.open();

希望您现在可以找到您要找的东西。有关详细信息,请查看此处的文档http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.SystemButton-property-TRASHhttp://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.Toolbar

由于