How to scrollIndex bottom on iOS in android it's working - titanium

how can I achieve scrollIndex on iOS? I tried following code:
var win = Ti.UI.createWindow({
title:'Row #50'
});
var tableData = [];
for(var i = 0; i < 100; i++){
tableData.push(
{title:'Row #'+i}
);
}
var table = Ti.UI.createTableView({
data:tableData
});
table.scrollToIndex(table.data[0].rows.length, Titanium.UI.iOS.TableViewScrollPosition.TOP);
win.add(table);
win.open();
How it will work?

invalide index, do this
table.scrollToIndex(table.data[0].rows.length - 1, Titanium.UI.iOS.TableViewScrollPosition.TOP);

Related

XMLHttpRequest main progress bar

I have created a progress bar to download images. All work fine just would like to show the download status of all files rather than individual.
var xhrList = [];
var link = [];
$('img').each(function() {
link.push($(this).attr("src"));
});
var width = $('.logo img').width();
$('#logo').css({'width': 0, 'overflow': 'hidden'});
for (var i=0; i< link.length; i++){
xhrList[i] = new XMLHttpRequest();
xhrList[i].open('GET', link[i], true);
xhrList[i].responseType = "blob";
console.log(xhrList[i]);
xhrList[i].onprogress = function(e) {
if (e.lengthComputable) {
ProgressPerc = parseInt((e.loaded / e.total) * 100);
$('#logo').stop().animate({'width': ProgressPerc + '%'},200);}
};
xhrList[i].send();
}
https://jsfiddle.net/ag8L9zmk/7/

Appcelerator Titanium JS: Table Alphabetical Index not working

I'm trying to get my head around using a the TableView index property to create native right hand alphabetical navigation - similar to that in the Apple iOS Contacts app - shown in the picture below:
I created a really simple example, with a set of rows, with row headers, but it doesn't work - whenever I tap on an index item, it just jumps to the top of the TableView again.
Here is my example code:
// Create the first TableViewSection
var section1 = Ti.UI.createTableViewSection({
headerTitle:'A'
});
// use a loop to add some rows
for (var i=0; i < 20; i++) {
section1.add(Ti.UI.createTableViewRow({
title:'Row '+i
}));
}
// do it all again...
var section2 = Ti.UI.createTableViewSection({
headerTitle: 'B'
});
for (var i=4; i < 10; i++) {
section2.add(Ti.UI.createTableViewRow({
title:'Row '+i
}));
}
// Now, here's our table, and we're setting the data to hold the sections
var tv = Ti.UI.createTableView({
data:[section1,section2]
});
// Create a table view index
var index = [
{ title: "A", index: 0 },
{ title: "B", index: 1 }
];
// Set the index on the table view
tv.setIndex(index);
$.index.open();
$.index.add(tv);
Here is an example for you dear
var win = Ti.UI.createWindow();
var table = Ti.UI.createTableView({});
var contacts = ["Adam", "Andrew", "Boris", "Claus", "Debby", 'Saba', 'Sana', 'Wahhab', 'Zohaib', 'Zzaid', 'Zzxad'];
var curheader = 'A';
var sectionArr = [];
var index = [];
for (var i = 0, lastL, l, currSection, ilen = contacts.length; i < ilen; i++) {
l = contacts[i].substr(0, 1);
if (lastL != l) {
index.push({
title : l,
index : i
});
currSection = Ti.UI.createTableViewSection({
headerTitle : l
});
sectionArr.push(currSection);
}
currSection.add(Ti.UI.createTableViewRow({
title : contacts[i],
}));
lastL = l;
}
table.setData(sectionArr);
table.index = index;
win.add(table);
win.open();
Thanks

Opening a new window on a tableview row click in titanium

I am trying to open a new window by click a row in tableview in titanium.
this is my code,
function listpage(){
var tabgroup=Ti.UI.createTabGroup();
var win = Ti.UI.createWindow({
title:'Listpage',
backgroundColor:'#fff'
});
var dataArray = [{
title:'Sunday',
hasChild:true,
test:'detail'}];
for(var i=0;i<dataArray.length;i++){
dataArray[i].color = '#000';
dataArray[i].font = {fontWeight:'bold',fontSize:20};
}
var tableview=Ti.UI.createTableView({
data:dataArray
});
tableview.addEventListener('click',function(e){
if(e.rowData){
Ti.API.info(e.rowData.title);
var winEvent = Titanium.UI.createWindow({
backgroundColor:'#fff',
url:e.rowData.test
});
winEvent.open({animation:true});
}
});
win.add(tableview);
win.open();
}
detail.js code :
var self = Ti.UI.createWindow({
title:'Detail',
color:'#000',
backgroundColor:'white'
});
var label = Ti.UI.createLabel({
text:'Hai',
color:'#000'
});
self.add(label);
What to do to open detail.js window by clicking tableview row.
Thankyou.
Surendra, this is something similar to your problem. It opens a window while you clicks on each row.
Code is
var wndHome = Ti.UI.createWindow({
backgroundColor : 'white'
});
var tableView = Ti.UI.createTableView({
top : 0
});
var tabledata = [];
for(var i = 0 ; i < 10; i++){
var row = Ti.UI.createTableViewRow({
title : 'Title of window',
url : 'details.js'
});
tabledata.push(row);
}
tableView.data = tabledata;
wndHome.add(tableView);
wndHome.open();
tableView.addEventListener('click', function(e){
var wndNewWindow = Ti.UI.createWindow({
backgroundColor : '#999966',
url : e.rowData.url
});
wndNewWindow.open();
});
details.js file
var self = Ti.UI.currentWindow;
var label = Ti.UI.createLabel({
text:'Hai',
color:'#000'
});
self.add(label);
Here I've given the url to details.js. If you want to use different windows, then keep the file names in an array and while creating the tableViewRow, you can simply add the array element as the url(eg: fileArray = ['file1.js', 'file2.js','file3.js'];).
Try this and change your code as per your requirement.

Titanium: Picker crashes with remote data

I am trying to fill remote data into picker, but it crashes.
here is the code:
var countryDataArray = [];
var picker_country = Ti.UI.createPicker
({
bottom:'-251dp'
});
win.add(picker_country);
getCountryList(); //to call web service
//Gets country list from the server
function getCountryList()
{
getCountry.onload = function()
{
var jsonString = JSON.parse(this.responseText);
var msg = jsonString.Message;
var success = jsonString.IsSuccess;
countryDataArray = jsonString.dsetData.CountryList;
Ti.API.log('countryList value:'+countryDataArray);
activity.hide();
if(countryDataArray.length > 0)
{
for (var i=0; i < countryDataArray.length ; i++)
{
data[i] = Ti.UI.createPickerRow(
{
title:countryDataArray[i].Name,
country_id:countryDataArray[i].ID,
fontSize:18
});
};
}
picker_country.add(data);
}
what's wrong with this code ? code works fine with static data !!!
static data :-
var data = [
{title:'Bananas',custom_item:'b',fontSize:18},
{title:'Strawberries',custom_item:'s',fontSize:20},
{title:'Mangos',custom_item:'m',fontSize:22,selected:true},
{title:'Grapes',custom_item:'g',fontSize:24}
];
Solved !!! I Don't why but I just assign the data to picker before adding the picker into the view and it get solved !
picker_country.add(data);
win.add(picker_country);

titanium TableRows are not inserted

i'm getting a JSON response properly but my problem is with showing it. what's wrong with my code.
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create base UI tab and root window
var win1 = Titanium.UI.createWindow({
title : 'Main Window',
backgroundColor : '#fff'
});
var listUrl = "http://magadhena.com/test/list.php?FCODE=5&USERID=1";
var NumberOfLists = [];
var lists;
var tableData = [];
var table = Ti.UI.createTableView({
top : 40,
left : 10,
width : 300
});
var txt1 = Titanium.UI.createTextField({
top : 10,
left : 10,
width : 250
});
var button1 = Ti.UI.createButton({
top : 10,
left : 270,
width : 30
});
var xhr = Ti.Network.createHTTPClient();
xhr.setTimeout(3000);
xhr.onload = function() {
lists = eval('(' + this.responseText + ')');
for(var i = 0; i < lists.length; i++) {
var userId = lists[i].userid;
// The userID
var listId = lists[i].listid;
// The ListID
var listName = lists[i].listname;
// The ListName
var Object1 = new list(userId, listId, listName);
// Ti.API.log("Object is ",Object1.listId);
NumberOfLists.push(Object1);
// Ti.API.log("the size of the Json array is" , NumberOfLists.length);
}
};
xhr.open("GET", listUrl);
xhr.send();
for(var i = 0; i < NumberOfLists.length; i++) {
var row = Ti.UI.createTableViewRow({
title : NumberOfLists[i].listName
});
Ti.API.log("populating the data table ", NumberOfLists[i].toString);
tableData.push(row)
};
// Ti.API.log("the size of table data is ", tableData.length);
table.setData(tableData);
win1.add(table);
win1.add(txt1);
win1.add(button1);
// Opening Window1
win1.open();
///// List Objects
function list(userid, listid, listname) {
this.userId = userid;
this.listId = listid;
this.listName = listname;
}
You need to put table.setData() into xhr.onload function. Since you defined the code outside of the function, NumberOfLists is empty until xhr.onload function executed