iOS Back button on centre of window using Titanium - titanium

I am trying to place a back button at centre of window. I am able to achieve the same using image view. However navigation to previous windows except for the very last are failing.
Lets say I have traversed three windows A->B->C. From window 'C' the button takes me to window 'B'. But from window 'B' click of same button evokes no response (ideally it should have taken me to window 'A')
The code I have used are as following
{
var imgView = Ti.UI.createImageView({
top:'50%',
left : 0,
image : "icons/back.png"
});
imgView.addEventListener('click', function(){
self.close();
});
}

Add the above line in your each file which containing the new window, since you're opening new windows using url method.
var currentWindow = Ti.UI.currentWindow;
Then close the window as follows
imgView.addEventListener('click', function(){
currentWindow.close();
});
This will close the current window, since currentWindow represents the active window
I'll add the working Example :
app.js
var win = Ti.UI.createWindow({
backgroundColor : 'white'
});
var back = Ti.UI.createButton({
title : 'To win1 ',
width : '70%'
});
back.addEventListener('click', function(){
var win1 = Ti.UI.createWindow({
url : 'win1.js',
backgroundColor : 'white',
layout : 'vertical'
});
win1.open();
});
win.add(back);
win.open();
win1.js
var self = Ti.UI.currentWindow;
var back = Ti.UI.createButton({
title : 'Back to home',
top : 20,
width : '70%'
});
var next = Ti.UI.createButton({
title : 'To win2',
top : 20,
width : '70%'
});
self.add(back);
self.add(next);
back.addEventListener('click',function(){
self.close();
});
next.addEventListener('click', function(){
var win2 = Ti.UI.createWindow({
url : 'win2.js',
backgroundColor : 'white',
layout : 'vertical'
});
win2.open();
});
win2.js
var self = Ti.UI.currentWindow;
var back = Ti.UI.createButton({
title : 'Back to win1',
top : 20,
width : '70%'
});
self.add(back);
back.addEventListener('click',function(){
self.close();
});

Related

Can not close root window of the navWindow. Close this window instead when trying to close modal

I get the following error even after having closed the modal.
Can not close root window of the navWindow. Close this window instead when trying to close modal
Below is my code
var mainWindow = Ti.UI.createWindow({
title : 'My Title',
barColor : topBarColor,
backgroundColor : 'white'
});
var modalWindow = Ti.UI.createWindow({
modal : true,
barColor : topBarColor,
backgroundColor : 'pink'
});
var navWin = Ti.UI.iOS.createNavigationWindow({
modal: true,
window: modalWindow
});
navWin.open();
This is how I close the windows
mainWindow.close();
modalWindow.close();
You have to pass the navigationWindow to the modal:
var navWin = Ti.UI.iOS.createNavigationWindow({
modal: true,
window: modalWindow
});
modalWindow.navWin = navWin;
navWin.open();
And then close it like this:
modalWindow.navWin.close();

window background image not showing on iphone Titanium

i have created tab group with single tab and window for tab , i have set background image for tab window, image is showing properly on android but in iPhone i cant see any image any solution to this problem?
var tabGroup = Titanium.UI.createTabGroup({
navBarHidden: true,
layout: 'vertical'
});
Ti.UI.Clipboard.setText('');
var db = require('dbhelper');
db.callDb();
var windowTitle = Ti.UI.createLabel({
color: '#fff',
text: 'IEMR LITE'
});
var win1 = Titanium.UI.createWindow({
backgroundColor: '#fff'
});
if (Ti.Platform.name === 'iPhone OS') {
win1.titleControl = windowTitle;
win1.barImage = 'images/actionbar3.png';
win1.hideTabBar();
} else {}
win1.backgroundImage = 'images/default_portrait.png';
I have tried this code and its works for me. also make sure you are providing correct image path.
var tabGroup = Titanium.UI.createTabGroup({
navBarHidden : true,
layout : 'vertical'
});
Ti.UI.Clipboard.setText('');
//var db = require('dbhelper');
//db.callDb();
var windowTitle = Ti.UI.createLabel({
color : '#fff',
text : 'IEMR LITE'
});
var win1 = Titanium.UI.createWindow({
backgroundColor : '#fff'
});
if (Ti.Platform.name === 'iPhone OS') {
win1.titleControl = windowTitle;
win1.barImage = '1.png';
win1.hideTabBar();
} else { }
win1.backgroundImage = '2.png';
var tab1 =Ti.UI.createTab({
window : win1
});
tabGroup.addTab(tab1);
tabGroup.open();
Try deleting your build folder and building for iPhone again. Sometimes after adding an image (or other binary resource), it doesn't get linked to the underlying built project properly until you do a clean build.

Close NavigationWindow (modal ) from another js file in Titanium IOS7

I am migrating a current project to 3.1.3 . I need a close button on the modal window so i had to use a NavigationWindow as suggested in the IOS7 migration guide. Here is what i have
btnSubscription.addEventListener('click', function(e) {
Ti.API.info('Subscription Button Clicked.');
openWindow("paymentsubscription.js", "Subscription");
});
function openWindow(url, title) {
var win = Ti.UI.createWindow({
url : url,
backgroundColor : 'white',
modal : true,
title : title
});
if (Titanium.Platform.osname !== "android") {
var winNav = Ti.UI.iOS.createNavigationWindow({
modal: true,
window: win
});
}
if (Titanium.Platform.osname !== "android") {
winNav.open();
}
else {
win.open();
}
}
Now on paymenttransaction.js i was previously doing this when i was using titanium 2.x
var mainWindow = Ti.UI.currentWindow;
var mainWinClose = Ti.UI.createButton({
style : Ti.UI.iPhone.SystemButtonStyle.DONE,
title : 'close'
});
if (Titanium.Platform.osname !== "android") {
mainWinClose.addEventListener('click', function() {"use strict";
mainWindow.close();
});
responseWindow.setRightNavButton(responseWinRightNavButton);
mainWindow.setRightNavButton(mainWinClose);
}
The problem i am facing is that i need to close winNav in the case of IOS and not win anymore. In paymenttransaction.js i was previously using
var mainWindow = Ti.UI.currentWindow;
But now i need to close the navigation window(winNav) and this does not hold good anymore. Is there anyway to do this? . Is there a Ti.UI.currentWindow equivalent for NavigationWindow ?
You aren't using the navigationWindow properly. You shouldn't be calling open() on a window when you use one.
You are looking for:
`winNav.openWindow(yourWindow)
Also when you are creating a new window, pass a pointer to your navigationWindow in the constructor, then you can close the window properly. Don't create a window like that use CommonJS's require() to return your window:
paymenttransaction.js:
function paymentTransactionWindow(navGroup, otherArgs) {
var mainWinClose = Ti.UI.createButton({
style : Ti.UI.iPhone.SystemButtonStyle.DONE,
title : 'close'
});
var win = Ti.UI.createWindow({
url : url,
backgroundColor : 'white',
modal : true,
title : title,
rightNavButton: mainWinClose
});
if (Titanium.Platform.osname !== "android") {
mainWinClose.addEventListener('click', function() {
navGroup.closeWindow(win);
});
return win;
}
module.exports = paymentTransactionWindow;
Then in your previousWindow:
PaymentTransactionWindow = require('/paymentTransactionWindow); //the filename minus .js
var paymentTransactionWindow = new PaymentTransactionWindow(winNav, null);
mainNav.openWindow(paymentTransactionWindow);
watch some of the videos on commonJS: http://www.appcelerator.com/blog/2011/08/forging-titanium-episode-1-commonjs-modules/

Trouble with EventListener in Titanium Studio

I am having trouble trying to add an Event Listener to my button. Here is what I have in my code.
var TabGroup = Titanium.UI.createTabGroup();
var Maps = Titanium.UI.createWindow({
backgroundImage:'/images/Background2.jpg'
});
var tab1 = Titanium.UI.createTab({
title: 'Maps',
icon: '/KS_nav_ui.png',
window: Maps
});
var scrollView = Titanium.UI.createScrollView({
contentWidth:'auto',
contentHeight:'auto',
top:0,
showVerticalScrollIndicator:false,
showHorizontalScrollIndicator:false
});
var view = Ti.UI.createView({
height:495,
width:300
});
var btnInnovations = Ti.UI.createButton({
height:75,
width:Titanium.UI.FILL,
backgroundImage:'/images/Innovations.jpg',
top:60
});
var btnOaks = Ti.UI.createButton({
height:75,
width:Titanium.UI.FILL,
backgroundImage:'/images/Oaks Campus.jpg',
top:145
});
var btnWHQ = Ti.UI.createButton({
height:75,
width:Titanium.UI.FILL,
backgroundImage:'/images/WHQ.jpg',
top:230
});
var btnRiverport = Ti.UI.createButton({
height:75,
width:Titanium.UI.FILL,
backgroundImage:'/images/Riverport.jpg',
top:315
});
var btnContinuous = Ti.UI.createButton({
height:75,
width:Titanium.UI.FILL,
backgroundImage:'/images/Continuous.jpg',
top:400
});
view.add(btnInnovations);
view.add(btnOaks);
view.add(btnWHQ);
view.add(btnRiverport);
view.add(btnContinuous);
scrollView.add(view);
Maps.add(scrollView);
TabGroup.addTab(tab1);
TabGroup.open();
btnInnovations.addEventListener('click', function(e){
var InnovationsFloors = Titanium.UI.createWindow({
title: 'Innovations Floors',
url:'InnovationsFloors.js'
});
InnovationsFloors.open({modal : true, backgroundImage:'images/Background1.jpg'});
The error I get in the emulator says cannot call method open of undefined and if I take out the Titanium.UI.currentTab.open(InnovationsFloors,{animation:true}); it won't even register the click...
First of all you cant have spaces in the name of your Window url field, rename your Innovations Floors.js file to InnovationsFloors.js.
Second part is that the attributes you are passing in to the open() command are not supported, it should be animated not animation, even so, you should not use this in this fashion, I refer you to the docs on this one.
Instead just do this:
Titanium.UI.currentTab.open(InnovationsFloors);
Or try this:
TabGroup.activeTab.open(InnovationsFloors);
If that doesn't work then it means you have not called open on your TabGroup so there is no current tab.
You could also always just try this and open a modal:
InnovationsFloors.open({modal : true});
if you want to open a window with a button try this works for me
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});
var label1 = Titanium.UI.createLabel({
color:'#999',
text:'I am Window 1',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
var button = Titanium.UI.createButton({
title: 'Hello',
top: 10,
width: 100,
height: 50
});
win1.add(button)
win1.add(label1);
button.addEventListener('click', function(e){
var win = Titanium.UI.createWindow({
title:'New Window',
backgroundColor:'#fff'
});
win.open();
});
tabGroup.addTab(tab1);
// open tab group
tabGroup.open();

Titanium Mobile: cant navigate between pages

i am new to Titanium and i am have 2 seemingly simple problems while trying to use it for the Android.
1) i am trying to navigate to the next page on click of a button. but instead it is showing me a blank black screen. i know my second page CreateNewMeetup.js is correct because i tried displaying it as the landing page of my app and it works. my codes are as follows:-
ApplicationWindow.js
...
var button = Ti.UI.createButton({
height:44,
width:'auto',
title:'Create New Meetup',
top:20
});
self.add(button);
button.addEventListener('click', function() {
var newWindow = Ti.UI.createWindow({
url : "/ui/common/CreateNewMeetupWindow.js",
fullscreen: false
});
newWindow.open();
});
return self;
CreateNewMeetupWindow.js
//CreateNewMeetUpView Component Constructor
function CreateNewMeetupWindow() {
var self = Ti.UI.createWindow({
layout : 'vertical',
backgroundColor:'white'
});
var contactsField = Ti.UI.createTextField({
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color : '#336699',
width : 400,
height : 60
});
self.add(contactsField);
var locationField = Ti.UI.createTextField({
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color : '#336699',
width : 400,
height : 60
});
self.add(locationField);
var lblNotifyMe = Ti.UI.createLabel({
color : 'black',
text : 'Notify me when s/he is',
textAlign : Ti.UI.TEXT_ALIGNMENT_LEFT,
width : 'auto',
height : 'auto'
});
self.add(lblNotifyMe);
var btnGo = Ti.UI.createButton({
title : 'Go',
height : 'auto',
width : 100
});
btnGo.addEventListener('click', function() {
// Check console
Ti.API.info('User clicked the button ');
});
self.add(btnGo);
return self;
};
2) after installing the app onto my device, i tried to launch it. the app shows momentarily (about 3 seconds maybe) and then it shuts down by itself. i guess its an app crash? but it works well on the emulator.
Titanium experts please help :$
You can use the following methods in your program to navigate between windows
Method 1
//Your app.js file
var button = Ti.UI.createButton({
height:44,
width:'auto',
title:'Create New Meetup',
top:20
});
self.add(button);
button.addEventListener('click', function() {
//By doing this you're opening a new window
var newWindow = Ti.UI.createWindow({
url : "ui/common/CreateNewMeetupWindow.js",//Provide the correct path here
fullscreen: false
});
newWindow.open();
});
//Your CreateNewMeetupWindow.js file
var newWindow = Ti.UI.currentWindow;
var contactsField = Ti.UI.createTextField({
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color : '#336699',
width : 400,
height : 60
});
newWindow.add(contactsField);
//You can add other controls here just like I added the contactsField
Method 2
var button = Ti.UI.createButton({
height:44,
width:'auto',
title:'Create New Meetup',
top:20
});
self.add(button);
button.addEventListener('click', function() {
var window = require('/ui/common/CreateNewMeetupWindow');
var newWindow = new window();
newWindow.open();
});
//Your CreateNewMeetupWindow.js file
function CreateNewMeetupWindow() {
var self = Ti.UI.createWindow({
layout : 'vertical',
backgroundColor:'white'
});
var contactsField = Ti.UI.createTextField({
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color : '#336699',
width : 400,
height : 60
});
self.add(contactsField);
//Add other controls here
return self;
}
module.exports = CreateNewMeetupWindow;
You can use any single method from above. Do not mix the methods together.
You can use the following link for references
http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Window-property-url
http://docs.appcelerator.com/titanium/latest/#!/api/Global-method-require
For your first problem, you are using the url property with a CommonJS object. So instead instantiate your window like this:
var newWindow = require("/ui/common/CreateNewMeetupWindow");
newWindow.open();
You would use the url property if your CreateNewMeetupWindow.js was not a CommonJS module.
Not sure what your second problem is, check your device logs and crash reports, otherwise there is no way to know what is going on.