我使用代码鸟库将twitter Feed集成到钛应用程序中。在那一刻,我只对文本和图像感兴趣。我在控制台中获得了这些元素,并且我的整个代码没有错误,但是,表格没有出现在应用程序中。我用正确的值替换了密钥和密钥。请参阅以下代码:
var tableView= Titanium.UI.createTableView({
zIndex:60
});
var rowData;
var win= Titanium.UI.createWindow({
backgroundColor:"white"
});
var Codebird = require("codebird");
var cb = new Codebird();
cb.setConsumerKey('consumer key', 'consumer secret');
var bearerToken = Ti.App.Properties.getString('TwitterBearerToken', null);
if(bearerToken == null){
cb.__call(
'oauth2_token',
{},
function (reply) {
var bearer_token = reply.access_token;
cb.setBearerToken(bearer_token);
Ti.App.Properties.setString('TwitterBearerToken', bearer_token);
fetchTwitter();
}
);
}
else {
Ti.API.info("We do have a bearer token...----------------------------------------------------------------------------");
cb.setBearerToken(bearerToken);
fetchTwitter();
}
function fetchTwitter(){
var data = [];
cb.__call(
'statuses/user_timeline',
"screen_name=ClassicHits4FM",
function (reply) {
// ...
Ti.API.info("newest and Example that should work just reply------------------------------"+ reply);
Ti.API.info("newest and Example that may work, reply's text ------------------------------"+ reply[0].text);
Ti.API.info("newest and Example that may work, reply's text ------------------------------"+ reply[0].user.profile_image_url);
for(i=0;i<10;i++){
data.push({
title: reply[i].text,
leftImage:reply[0].user.profile_image_url
});
//alert("Data test ----------------------------------"+data[i].title);
}
//Ti.API.info("newest Example that should work, user profile image ------------------------------"+ reply[0].user[0].profile_image_url);
},
true // this parameter required
);
rowData=[];
for(i=0;i<data.length;i++){
var img= Titanium.UI.createImageView({
image:data[i].leftImage,
left:5,
bottom:5,
top:5,
height: '120dp',
width: '120dp'
//height: "120%",
//width: "34%"
});
var title=Titanium.UI.createLabel({
text:data[i].title,
color: 'black',
//left: "38%",
left: '128dp',
right: '4dp',
font:{ fontSize: '15sp', font: 'Droid Serif'}
});
var row=Titanium.UI.createTableViewRow({
height: TI.UI.SIZE
});
row.add(img);
row.add(title);
rowData.push(row);
}
tableView.setData(rowData);
win.add(tableView);
}
win.open();
答案 0 :(得分:0)
var tableView= Titanium.UI.createTableView({
zIndex:60,
width : Ti.UI.FILL,
height: Ti.UI.FILL
});
答案 1 :(得分:0)
解决了这个问题,将所有代码从'rowdata'开始移动到'cb .__ call'语句块中。
另外,在我的行定义中,我写了 TI.UI.SIZE ,需要 Ti.UI.SIZE