未调用垃圾按钮的回调

Callback of trash button not called

我正在使用 Titanium Alloy 开发我的第一个应用程序。对于 iOS,我使用原生 iOS 垃圾桶按钮,使用 systemButton="TRASH"。对于那个按钮,我还有一个 onClick 处理程序,onClick="deleteReckon"。但是,deleteReckon 方法不会在单击垃圾按钮时调用。

这是 iOS 的 "reckonDetails.xml" 视图(因此,包含在 "views" 目录的 "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>

这是 "reckonDetails.js" 控制器:

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(...);语句来检查函数是否被调用,但是没有..

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

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

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

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

我已经在 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-TRASH and http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.Toolbar

谢谢