Transfer information or data between two tabs
Hi Experts,
Can someone show me simple example to transfer information / data between two views of different tabs.
If i have Tab1 with tableView11 and another Tab2 with tableView21. When user select item from Tab1 -> tableView11, that item get added in to Tab2 -> tableView21. What I want to do is I want to transfer the information from tableView11 to tableView21.
I know one way to do it is to wrote in to the file and call that file from tableView21.But I think that is not the best solution. It is a same application. There must be some way to transfer the information in above mentioned situation.
4 Answers
-
Accepted Answer
Sorry I dont have kitchensink example with me at moment. (Couldn't get it to work on my windows pc).
Anywayz. Hopefully my following words are understandable.
Basically you can see Ti.App as a global object that lives along with your applciation, and it's accessible from any point of your application. (any windows or views).
Personally, I used it more often for situation when I need to fireEvents from the global-prespective.
However it can also be used as a placeholder for passing objects.
As stated in my previous example. The Ti.App.arrayPassMe was declared and assigned to aArray in one window prespective and because Ti.App is in a global context, arrayPassMe is accessible from any other context within the applicaiton.
In Javascript, it's not necessary to declare a property for a object before you use it. By doing Ti.App.arrayPassMe = xxxx, you are simply declaring a property for the object Ti.App named arrayPassMe and assign it to the reference of xxxx.
One great usage for Ti.App is how I declare a global constant called sBarColor, which will be used in all places within the application when trying to create a Window object. This is a great way of keeping all new window barColor property consistant, and if you wish to change the color anytime in the future. All you have to do is change the value of that global variable. For example:
// I declare this in the app.js Ti.App.sBarColor = '#333'; // A dark color code for any barColor // Later in the application, when I create a new window, I can always reference to that barColor // windows1.js var winNew = Ti.UI.createWindow({ barColor: Ti.App.sBarColor; });
-
You could use the Ti.App global object to transfer the information you need to any other window or tabs.
For Example, I wish to pass a array from window 1 to window 2 without setting window's variables.
// Inside your first window // Declare a new array var aArray = ['a1', 'a2']; // Assign it to the global reference Ti.App.arrayPassMe = aArray; // after new window or tab been loaded window2.arrayGetMe = Ti.App.arrayPassMe; // Debug log Ti.API.info(window2.arrayGetMe[0]); // [INFO] a1 // If you wish, you can always decease it after use Ti.App.arrayPassMe = null;
-
can you please elaborate more on this or point me to some kitchen sink example or documentation about how to implement it?
-
can you please elaborate more on this or point me to some kitchen sink example or documentation about how to implement it?