gpt4 book ai didi

javascript - 在 tableViewRow 中交换图像

转载 作者:行者123 更新时间:2023-11-29 02:59:56 25 4
gpt4 key购买 nike

我正在使用 Titanium 构建一个 iOS 7 应用程序。我有一个显示几条数据的 tableView。每个 tableViewRow 的高度为 180px。我想在左上角放置一个 60px x 60px 的图像。单击图像后,我想将图像更改为另一个图像。这是我到目前为止的代码:

var tableview = Ti.UI.createTableView({
backgroundColor : 'transparent',
top : '0px',
width : '99%',
bottom : '10px',
color : '#000',
contentHeight : 'auto'
});

tableview.addEventListener('click', function(e) {
if(e.row.image == 'images/nomatch.png') {
e.row.image = 'images/match.png';
} else {
e.row.image = 'images/nomatch.png';
}
});

//Then I get my data from the database and set up my row

row = Ti.UI.createTableViewRow({
backgroundImage : 'images/openmatchesrowbackground.png',
width : '90%',
height : '180px'
});

var acceptmatchView = Ti.UI.createView({
left : '0px',
top : '0px',
width: '60px',
height: '60px'
});

var acceptmatch = Ti.UI.createImageView({
image : 'images/nomatch.png',
left : '0px',
top : '0px',
width: '60px',
height: '60px'
});

//Then I add 7 more labels to the row and add the images and labels to the views and the views to the windows

acceptmatchView.add(acceptmatch);
row.add(acceptmatchView);
...

如果我使用行属性“leftImage”,我将失去将其定位在左上角的功能,并且代码直到第一次点击后才会显示图像,但随后图像会发生变化。我已经尝试了一些我发现的其他代码,但没有一个代码能在这种情况下正常工作。

最佳答案

您无法使用 e.row.image 将图像分配给 acceptmatch

根据您的设计,acceptmatchacceptmatchView 的子级,而 acceptmatchView 是您的 row 的子级。

Your row
- > Children[0] - acceptmatchView
-> Children[0] - acceptmatch

因此您可以为其分配图像,如下所示:

tableview.addEventListener('click', function(e) {
var imageView = e.row.children[0].children[0];
if(imageView.image == 'images/nomatch.png')
{
imageView.image = 'images/match.png';
}
else
{
imageView.image = 'images/nomatch.png';
}
});

关于javascript - 在 tableViewRow 中交换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23436873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com