Moving views

You must Login before you can answer or comment on any questions.

I am wanting to move to another view and display the results from the previous view in that window. I cannot figure out how to achieve this.

My code in my app js is:

var SearchView = require('/ui/SearchView');
var ResultsView = require('/ui/ResultsView');
var MenuView = require('/ui/MenuView');
var AboutView = require('/ui/AboutView');
 
var search = new SearchView();
 
var results = new ResultsView();
 
var about = new AboutView();
// Each row with a view property when clicked will change to that view (any view works except tabgroups and windows)
// If the row does not have a view property, but the switch event still fires
var data = [
    { title:'Search', hasDetail:true, view: search },
    { title:'Results', hasDetail:true, view: results },
    { title:'About', hasDetail:true, view: about }
];
 
var menu = new MenuView({
    rowData: data
});
When I click search in menu i get sent to searchView which is:
var SearchView = function(args){
    var self = Ti.UI.createView({
        backgroundColor:'white'
    });
    var results = new ResultsView();
    var searchLabel = Ti.UI.createLabel({
         font : {
         fontSize : 30,
         fontFamily : 'Helvetica Neue'
     },
        top: 150,
        text: "Search"
 
    });
 
    var searchField = Ti.UI.createTextField({
        top:200,
        width: 200,
        borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
        hintText: "Search",
        returnKeyType : Titanium.UI.RETURNKEY_SEARCH
    });
    self.add(searchLabel);
    self.add(searchField);
 
    searchField.addEventListener('return', function(event) {
    var url = "http://xxxxxxx/xxxx/xxxxxxxxxxxx?search=" + event.value;
    var response = getSearch(url);
 
});
 
function getSearch(url) {
 
    var client = Ti.Network.createHTTPClient({
 
        // function called when the response data is available
        onload : function(e) {
            Ti.API.info("Received text: " + this.responseText);
 
            var jsonObj = JSON.parse(this.responseText);
            //slidingMenu.changeView(ResultsView);
            //getShow(jsonObj);
 
        },
        // function called when an error occurs, including a timeout
        onerror : function(e) {
            Ti.API.debug(e.error);
            alert('error');
        },
        timeout : 5000 // in milliseconds
    });
    // Prepare the connection.
    client.open("GET", url);
    // Send the request.
    client.send();
}
 
 
 
 
    return self;
};
 
module.exports = SearchView;
I am then wanting the focus to move to the results view and pass the JSON object to there too. Because of how this is programmed it must go the view and not create a new window.

Any Ideas? Thanks.

— asked 7 months ago by Michael Sagar
1 Comment
  • Ideally i would like to go to the results view that is created in app.js

    — commented 7 months ago by Michael Sagar

1 Answer

Accepted Answer

I dont really get your problem.... so you want to pass the JSON from search view to result view?... maybe if you just wait till you have your search´s JSON to create your "var ResultsView = require('/ui/ResultsView');" and then create a instance of that as "var rv=ResultsView(JSON object)"

— answered 7 months ago by Majid Mazinani
answer permalink
2 Comments
  • thanks for your reply, I am wanting to also make the results view in focus so its viewable.

    — commented 7 months ago by Michael Sagar

  • focus the view? if you create it at the end it should come on top.... try using show() and hide()..maybe if you hide the other views...

    — commented 7 months ago by Majid Mazinani

Your Answer

Think you can help? Login to answer this question!