2011-12-28 90 views
1

希望这是我今天最后一个问题......哦哦的Android钛覆盖(清表)

这样的IM填充了从用户输入表:

var textField = Ti.UI.createTextField({ 
hintText:"Zoeken over twitter", 
backgroundColor:"#fff", 
borderColor:"#fff", 
borderWidth:1, 
borderRadius:10, 
left:10, 
right:10, 
top:10, 
height:50 
}); 
Ti.UI.currentWindow.add(textField); 

var buttonSearch = Ti.UI.createButton({ 
title:"Zoeken", 
left:10, 
right:10, 
top:70, 
height:50 
}); 
Ti.UI.currentWindow.add(buttonSearch); 

buttonSearch.addEventListener("click", function() { 

    if (typeof tableview == 'undefined') { 

    } else { 
     Ti.UI.currentWindow.remove(tableview); 
    } 

var twitterUserName = textField.value; 
var httpClient = Ti.Network.createHTTPClient(); 
httpClient.timeout = 10000; 
httpClient.open("GET","http://api.twitter.com/1/statuses/user_timeline.json?count=10&screen_name=" + twitterUserName); 


var twitterData = []; 
httpClient.onload = function() { 
    try { 

     var tweets = JSON.parse(this.responseText); 
     for (var i=0; i < tweets.length; i++) { 


for (var i=0; i < tweets.length; i++) { 

      var tweetText = tweets[i].text; 
      var user = tweets[i].user.screen_name; 
      var avatar = tweets[i].user.profile_image_url; 
      var created_at = tweets[i].created_at; 

      var row = Ti.UI.createTableViewRow({hasChild:true, 
       height:'auto'}); 

var postView = Ti.UI.createView({ 
       height:'auto', 
       layout:'vertical', 
       left:5, 
       top:5, 
       bottom:5, 
       right:5 
      }); 

      var avatarImageView = Ti.UI.createImageView({ 
       image:avatar, 
       left:0, 
       top:0, 
       height:48, 
       width:48 
      }); 

      postView.add(avatarImageView); 

      var userLabel = Ti.UI.createLabel({ 
       text:user, 
       left:54, 
       width:120, 
       top:-48, 
       bottom:2, 
       height:16, 
       textAlign:'left', 
       color:'#444444', 
       font:{fontFamily:'Trebuchet MS',fontSize:14, 
        fontWeight:'bold'} 
      }); 

      postView.add(userLabel); 

      var dateLabel = Ti.UI.createLabel({ 
       text:created_at, 
       right:0, 
       top:-18, 
       bottom:2, 
       height:14, 
       textAlign:'right', 
       width:110, 
       color:'#444444', 
       font:{fontFamily:'Trebuchet MS',fontSize:12} 
      }); 

      postView.add(dateLabel); 

      var tweetTextLabel = Ti.UI.createLabel({ 
       text:tweetText, 
       left:54, 
       top:0, 
       bottom:2, 
       height:'auto', 
       width:236, 
       textAlign:'left', 
       font:{fontSize:14} 
      }); 

      postView.add(tweetTextLabel); 
      row.add(postView); 
      twitterData[i] = row; 
     } 


    } 
    var tableview = Titanium.UI.createTableView({data:twitterData, 
      minRowHeight:58, top:130}); 
     Ti.UI.currentWindow.add(tableview); 

    } catch(E) { 
     alert(E); 
    } 
}; 
httpClient.send(); 
}); 

问题是我的第二搜索覆盖我的第一次搜索witouth删除表,所以它显示两个表在彼此之上...你可以看到我试图删除与typeoff = undefined的前一张表,但这不起作用...任何想法如何我可以删除以前填满的表格吗?我试图做一个删除,但这显然会引发错误,因为表格不存在在第一...

+0

不要在onload()中创建一个表,在函数中定义一个表并尝试用于添加行的setData()方法。 – 2011-12-29 10:03:31

回答

1

这就是我做到这一点。

if (tableview.data.length > 0) { 
    for (var i = tableview.data[0].rows.length-1; i >= 0; i--) { 
     tableview.deleteRow(i); 
    } 
}