I have code that gets a json list of photo urls from a server, puts them into an array, and uses that array to display a scrolling gallery using 3 views(one before, current, after). In version 1.8.2 it worked perfectly, but as soon as I try to use 2.x(2.0.2 or 2.1.0), it starts randomly throwing "invalid image type. expected TiBlob... was: __NSCFString..." This error is common when there truly is something wrong with the parameter that you send it, but in my case it is not. IOS only.. tested with 5.0 and 5.1. The error occurs randomly at random places, but always when you are assigning the .image on a view from the array. It i not tied to any given photo, the urls have no spaces in them.
I am open to suggestions about doing this differently, but am quite annoyed that something that worked in one version of Titanium, now no longer works with no mention about anything being deprecated or changed.
I believe I NEED version 2x to be able to publish this as an IPad app.. it's still very convoluted.. I cannot get the 1.8.2 version to publish to an IPad without having the 1x/2x button, but that works with 2.x(and is an entire different issue)
var win = Titanium.UI.currentWindow; //create image arrays, index variables and view variables var nextImageIndex; var imageNameArray2 = []; var imageIDArray2 =[]; var scrollingView; var vw, vw1; //iphone scroll listener. detects left and right swipes. only gets 3 images at a time. one on either side of the image showing //for memory purposes. function scrollListener(e) { if(e.currentPage == 2 && nextImageIndex < imageNameArray2.length - 2) { //alert('swipe right'); nextImageIndex += 1; vw = scrollingView.views[0]; scrollingView.removeView(vw); vw.image=imageNameArray2[nextImageIndex + 1]; vw.id=imageIDArray2[nextImageIndex + 1]; scrollingView.views[0] = scrollingView.views[1]; scrollingView.views[1] = scrollingView.views[2]; scrollingView.addView(vw); scrollingView.currentPage = 1; } else if(e.currentPage == 0 && nextImageIndex > 1) { //alert('swipe left'); nextImageIndex -= 1; vw = scrollingView.views[2]; vw1 = scrollingView.views[1]; scrollingView.removeView(vw); scrollingView.removeView(vw1); vw.image=scrollingView.views[0].image; scrollingView.addView(vw); scrollingView.addView(vw1); //alert(scrollingView.views.length); scrollingView.views[1].id = imageIDArray2[nextImageIndex]; scrollingView.currentPage = 1; scrollingView.views[0].image = imageNameArray2[nextImageIndex - 1]; }else if(nextImageIndex == 1){ scrollingView.views[0].id = imageIDArray2[nextImageIndex-1]; }else if(nextImageIndex == imageNameArray2.length - 2){ //alert('got here'); } } //creates the ios images with their event listeners attached function createIOSViewer(imageNameArray,imageIDArray){ //save the image arrays returned from the server imageNameArray2 = imageNameArray; imageIDArray2 = imageIDArray; //create image views imageView1 = Titanium.UI.createImageView({width:Ti.Platform.displayCaps.platformWidth,height:Ti.Platform.displayCaps.platformHeight-124}); imageView2 = Titanium.UI.createImageView({width:Ti.Platform.displayCaps.platformWidth,height:Ti.Platform.displayCaps.platformHeight-124}); imageView3 = Titanium.UI.createImageView({width:Ti.Platform.displayCaps.platformWidth,height:Ti.Platform.displayCaps.platformHeight-124}); //create scroll view scrollingView = Titanium.UI.createScrollableView({ views:[imageView1, imageView2, imageView3], backgroundColor:"#000" }); //assign images to the scrollview with ids scrollingView.views[0].image = imageNameArray2[0]; scrollingView.views[1].image = imageNameArray2[1]; scrollingView.views[2].image = imageNameArray2[2]; scrollingView.views[0].id = imageIDArray2[0]; scrollingView.views[1].id = imageIDArray2[1]; scrollingView.views[2].id = imageIDArray2[2]; nextImageIndex = 1; //assign the scrolllistener function to the scrollable view scrollingView.addEventListener('scroll', scrollListener); //add views win.add(scrollingView); } // create the server request var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function() { //else store the image urls var pics = eval('('+this.responseText+')'); var imageNameArray = []; var imageIDArray = []; for(var i=0; i < pics.projectphoto.length; i++){ imageNameArray[i] = "http://" + pics.projectphoto[i].photourl; //WE MAY WANT TO USE t=f for smaller images to better load times depending on sizes.. check it out. imageIDArray[i] = pics.projectphoto[i].projectid; } createIOSViewer(imageNameArray,imageIDArray); } var xhrurl='http://www.sunguardglass.com/oracleprd/groups/sunguard/documents/web_content/gi_018780.hcst?countryid=US&language=EN'; if(Ti.Network.online){ // open the client xhr.open('GET',xhrurl); // send the data xhr.send(); }
1 Answer
have you solved your problem?
Your Answer
Think you can help? Login to answer this question!