I have a situation where I need to choose from 3 possible values to update a data item with in a remote database. I need to this without using the picker method. I chose tabbed bar with 3 tabs. The values loaded into the tabbed bar are 'admin','mgr' and 'assoc'. The choosing and database updating is done in a sibling window which is created by listener attached to the corresponding label that exposes the data to be changed. All this works just fine, however, not unexpectedly, the value that was changed in the sibling window is not shown changed in the parent window because upon returning back to the parent window there was no refresh done from the database.
My questions regarding this situation are:
1) Is there a way to detect a "return state" so that it may be followed by code that refreshes the page?
2) Is there a way to return back to the grand parent window? (In my case this would be best!)
3) Can a small window withing the parent window be created to do the change without leaving the parent window? Much like it can be done with pickers.
4) Is there a best solution to this problem?
Thank you in advance for your help!
Alex ----------------- Information abut my Titanium dev system -----------------
1) Application Type: Mobil
2) Titanium SDK version: 2.0.1 (04/12/12 16:33 999c68a)
3) IOS 5.0, Xcode 4.3
4) IOS Simulator
5) Host Operating System: Mac OS X version 10.7
6) Ti Studio build: 2.1.0.201206251749, Date: 25/6/2012
3 Answers
Thank you very much for your suggestions Stephen. I will try all of them tomorrow except the last one in which you suggest that I could pass an update function as a callback passed to my window. I presume you meant parent window. I cannot visualize how that can be done. If you could elaborate a bit more on that subject I'll be willing try that too. Thanks again!
Stephen, Here is the main part of my code that I changed per your suggestion #1. It woks partially. If I click on the text display of the 4th iteration of thisType the replacement of the text works OK, however iterations 1 thru 3 do not. I believe that thisType.text inf the close function only refers to the last row. Interestingly, even that text replacement has a problem. If I replace the text with a shorter or equal length text there is no problem, however if I replace the text value with a longer that the current value, the value will be abbreviated (i.e. if "mgr" to be replaced with "associate" the new value will be "a.."). Can you please help me with these problems?
var tableData = [];
for (var i = 0; i < 4; i++) {
var thisLabelName = Ti.UI.createLabel({
color: '#000', text : gx_name[i],
width: 'auto', left: 5
});
var thisType = Titanium.UI.createLabel({
color: 'blue',
text: gu_type[i],
width: 'auto',
textAlign: 'left',
bottom: 0,
left: 25,
height: 14
})
thisType.addEventListener('click', function(e) {
var type = e.source.text;
Ti.API.info('thisTiype\'s text value: ' + e.source.text);
var row = e.source.getParent();
var guid = row.children[0].objectId;
var gutype = row.children[0].objectType;
Titanium.App.Properties.setString('user_type',gutype);
var winUserType = Ti.UI.createWindow({
url:'tabbedbar.js',
title:'Set user type'
});
Titanium.UI.currentTab.open(winUserType,{animated:true});
inUserType.addEventListener('close',function(){
gutype = Titanium.App.Properties.getString('user_type');
ype.text = gutype;
});
})
var thisRow = Ti.UI.createTableViewRow({
layout: &quot;vertical&quot;,
textAlign: &quot;center&quot;,
selectedColor: &quot;black&quot;,
touchEnabled : true,
left: 1,
height: 50,
top: 1
});
thisRow.add(thisLabelName);
thisRow.add(thisType);
tableData.push(thisRow);
}
var table = Ti.UI.createTableView({
style : Ti.UI.iPhone.TableViewStyle.BORDERED,
backgroundColor : 'transparent',
borderColor : '#969',
data : tableData,
separatorColor : '#000',
top : 0,
width : 'auto'
});
It all depends really on how your code is laid out. If the parent and the child are in the same scope, the objects in the child could interact with the objects of the parent.
ex:
var mylabel, myparentwindow, mychildwindow; myparentwindow = Ti.UI.createWindow(); mylabel = Ti.UI.createLabel({text:'I be a label'}); mylabel.addEventListener('click',function(){ mychildwindow.open(); } mychildwindow = Ti.UI.createWindow(); mychildwindow.addEventListener('close',function(){ mylabel.text = 'My parents child window was closed'; } myparentwindow.add(mylabel);
Your Answer
Think you can help? Login to answer this question!