Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 交换tableViewRow中的图像_Javascript_Ios_Titanium - Fatal编程技术网

Javascript 交换tableViewRow中的图像

Javascript 交换tableViewRow中的图像,javascript,ios,titanium,Javascript,Ios,Titanium,我正在用钛制作一个iOS 7应用程序。我有一个tableView,可以显示多个数据段。每个tableViewRow的高度为180像素。我想在左上角放置一个60像素乘60像素的图像。单击图像时,我想将图像更改为其他图像。以下是我目前掌握的代码: var tableview = Ti.UI.createTableView({ backgroundColor : 'transparent', top : '0px', width : '99%', bottom : '10px', color : '#

我正在用钛制作一个iOS 7应用程序。我有一个tableView,可以显示多个数据段。每个tableViewRow的高度为180像素。我想在左上角放置一个60像素乘60像素的图像。单击图像时,我想将图像更改为其他图像。以下是我目前掌握的代码:

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

根据您的设计,
acceptmatch
acceptmatchView
的子级,它是
行的子级

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';
    }
});