4

我必须删除当前视图在同一个视图中......如果我在父视图中,我可以做

parentView.remove(childView);

但是在子视图上我没有parentView所以我怎样才能弹出childView以让parentView在顶部,就像在 iOS 中按下后退按钮时发生的那样?请帮忙

这是我的 childView 文件..

function DetailView(){


var self = Ti.UI.createView({
    backgroundColor:'#fff'
});
// Create a Button.
var aButton = Ti.UI.createButton({
    title : 'aButton',
    height : '50',
    width : '100',
    top : '10',
    left : '20'
});

// Listen for click events.
aButton.addEventListener('click', function() {

     alert('\'aButton\' was clicked!');

我必须在按下 aButton 时导航回来,我应该放在这里做什么

});

// Add to the parent view.
self.add(aButton);


return(self);
 }
module.exports = DetailView;

这是我的父母观点:

    //FirstView Component Constructor
    var self = Ti.UI.createView();

    function FirstView() {
//create object instance, a parasitic subclass of Observable


var DetailView = require('ui/common/DetailView');

var data = [{title:"Row 1"},{title:"Row 2"}];
var table = Titanium.UI.createTableView({
    data:data
    });
table.addEventListener('click', rowSelected);

self.add(table);

return self;
    }

    function rowSelected()
    {
var DetailView = require('ui/common/DetailView');

//construct UI
var detailView = new DetailView();
self.add(detailView);

    }

    module.exports = FirstView;
4

1 回答 1

4

此时您可以将 parentView 传递给子视图的构造函数:

//construct UI
var detailView = new DetailView(parentView);
self.add(detailView);

并在点击事件中

aButton.addEventListener('click', function() {
   if ( parentView != null ) {
       parentView.remove(childView);
    }
});
于 2012-05-08T11:46:13.247 回答