我有点击eventListener
时调用的钛地图,它第一次工作正常,但是当我导航到同一窗口中的另一个视图并返回地图时,它会给我一个空白视图任何错误。
检查以下代码:
var winStores = Titanium.UI.currentWindow;
winStores.backgroundColor = '#eeeeee';
var store_id = winStores.store_id;
var mainView = Titanium.UI.createView({});
var pageLoad = Titanium.UI.createActivityIndicator({
message:'Loading...'
});
// top view
function setContent()
{
}
// store info
function store_info()
{
}
// store review
function store_review()
{
}
// store offers
function store_offers()
{
}
// store map
var annotation = [];
var mapViewStore = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
animate:true,
regionFit:true,
userLocation:false,
annotations:annotation
});
function store_map()
{
var xmlhttp = Titanium.Network.createHTTPClient();
winStores.remove(mainView);
// main view
mainView = Titanium.UI.createView({
top: 160,
bottom:60
});
xmlhttp.onload = function()
{
pageLoad.show();
var doc = this.responseXML.documentElement;
var stores = doc.getElementsByTagName("store").item(0);
var lat = stores.getAttribute("latitude");
var lon = stores.getAttribute("longitude");
var franchise = stores.getElementsByTagName("franchise").item(0);
var merchant = franchise.getElementsByTagName("merchant").item(0);
var merchant_name = merchant.getAttribute("name");
if(stores.getAttribute("webstore") === '1' || stores.getAttribute("webstore") === 1)
{
var url = stores.getAttribute("url");
Titanium.Platform.openURL(url);
}
else
{
annotation = Titanium.Map.createAnnotation({
latitude:lat,
longitude:lon,
title:merchant_name,
subtitle:'',
pinImage:'../images/map-pin.png',
animate:true
});
mapViewStore.addAnnotation(annotation);
var region={latitude:lat,longitude:lon};
mapViewStore.setLocation(region);
mapViewStore.zoom(+1);
}
mainView.add(mapViewStore);
winStores.add(mainView);
pageLoad.hide();
}
xmlhttp.open('GET', 'http://www.abc');
xmlhttp.send();
}
// store photo
function store_photo()
{
}
// top content call
setContent();
// initial call to store info
store_info();
// Footer view
var ImgStoreInfo = Titanium.UI.createImageView({
url:'../images/icons/info.png',
height:60,
width:64,
left:0,
borderColor:'#666',
borderWidth:1,
backgroundColor:'#333',
touchEnabled:true,
zIndex:1
});
var ImgStoreReview = Titanium.UI.createImageView({
url:'../images/icons/review.png',
height:60,
width:64,
left:64,
borderColor:'#666',
borderWidth:1,
backgroundColor:'#333',
touchEnabled:true,
zIndex:2
});
var ImgStoreOffers = Titanium.UI.createImageView({
url:'../images/icons/offer.png',
height:60,
width:64,
left:128,
borderColor:'#666',
borderWidth:1,
backgroundColor:'#333',
touchEnabled:true,
zIndex:3
});
var ImgStoreMap = Titanium.UI.createImageView({
url:'../images/icons/web.png',
height:60,
width:64,
left:192,
borderColor:'#666',
borderWidth:1,
backgroundColor:'#333',
touchEnabled:true,
zIndex:4
});
var ImgStorePhoto = Titanium.UI.createImageView({
url:'../images/icons/photo.png',
height:60,
width:64,
left:256,
borderColor:'#666',
borderWidth:1,
backgroundColor:'#333',
touchEnabled:true,
zIndex:5
});
var footerView = Titanium.UI.createView({
borderRadius:0,
backgroundColor:'#333',
bottom:0,
height:60
});
footerView.add(ImgStoreInfo);
footerView.add(ImgStoreReview);
footerView.add(ImgStoreOffers);
footerView.add(ImgStoreMap);
footerView.add(ImgStorePhoto);
winStores.add(footerView);
// Click event listener for footer
ImgStoreInfo.addEventListener('click', function(e){
store_info();
});
ImgStoreReview.addEventListener('click', function(e){
store_review();
});
ImgStoreOffers.addEventListener('click', function(e){
store_offers();
});
ImgStoreMap.addEventListener('click', function(e){
store_map();
});
ImgStorePhoto.addEventListener('click', function(e){
store_photo();
});
每次点击任意imageview
时,mainView
都会移除当前视图并添加新视图。我在很多论坛上搜索过但找不到任何解决方案。