Use titanium, delete current view or popup view

I need to delete the current view in the same view ... if I'm in the parent view, I can do

parentView.remove(childView); 

but being in a child view, I don’t have a parentView , so how can I post a childView to get the parentView from above, since this happens when I press the back button in iOS? please, help

Here is my childView file.

 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!'); 

I need to go back to pressing aButton, what should I do here to do this

 }); // Add to the parent view. self.add(aButton); return(self); } module.exports = DetailView; 

Here is my parental view:

  //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
source share
1 answer

You can pass the parent to the constructor of the child view at this point:

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

and in the click event

 aButton.addEventListener('click', function() { if ( parentView != null ) { parentView.remove(childView); } }); 
+4
source

Source: https://habr.com/ru/post/1411254/


All Articles