Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Event Listeners for multiple objects in a row

$
0
0

I am building a Titanium iOS app using SDK 3.2.2, Studio 3.2, OS 10.9. I have a tableview that has two images and some other labels on each row. I want to be able to click on each one of the images and swap for other images and I want to be able to click on a label like a phone number and bring up the dialer. I got a suggestion to add a property like 'action' to my objects and then reference it in the click listener. I tried to implement that suggestion and must have made a mistake or omitted something critical as the code still does not work. Here is some of my code:

//First I create my table and then call a php file to return some JSON data, then I create my row and define an image
 
row = Ti.UI.createTableViewRow({
    backgroundImage : 'images/openmatchesrowbackground.png',
    selectionStyle : Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE,
    width : '100%',
    height : '180pt',
    rowId : i
    });
 
    var acceptmatchView = Ti.UI.createView({
        left : '0pt',
        top : '0pt',
        width : '60pt',
        height : '60pt'
        });
 
    var acceptmatch = Ti.UI.createImageView({
        image : 'images/nomatch.png',
        left : '0pt',
        top : '0pt',
        width : '60pt',
        action: 'swapImages',
        height : '60pt'
        });
 
//Then I add some labels and add everything to the row - Now create my event listener
 
        tableview.addEventListener('click', function(e) {
        var imageView = e.row.children[0].children[0];
 
    if (imageView.image == 'images/nomatch.png') {
        imageView.image = 'images/match.png';
 
    var matchSelected = json.openmatches[e.rowData.rowId];
 
        var alertWindow = Titanium.UI.createAlertDialog({
            title : 'Accept This Match?',
            message : 'Are you sure you want to accept this match?' + '\n' + matchSelected.matchtype + '\n' + 'Time: ' + matchSelected.datetime + '\n' + 'At: ' + matchSelected.courtname,
            cancel : 1,
            buttonNames : ['Yes', 'Cancel']
        });
alertWindow.addEventListener('click', function(ev) {
            Titanium.API.info("cancel " + ev.cancel);
            Titanium.API.info("index " + ev.index);
switch(e.source.action){
 
                case 'swapImages':
 
                    break;
                case 'swapImages':
 
                    imageView.image = 'images/nomatch.png';
                    break;
 
            }
        });
        alertWindow.show();
 
    } else {
 
        imageView.image = 'images/nomatch.png';
        var alertWindow = Titanium.UI.createAlertDialog({
            title : 'Cancel This Match?',
            message : 'Are you sure you want to cancel this match?',// + '\n' + matchSelected.matchtype + '\n' + 'Time: ' + matchSelected.datetime + '\n' + 'At: ' + matchSelected.courtname,
            cancel : 1,
            buttonNames : ['Yes', 'Keep Match']
        });
 
        alertWindow.addEventListener('click', function(ev) {
            Titanium.API.info("cancel " + ev.cancel);
            Titanium.API.info("index " + ev.index);
 
            switch(e.source.action) {
                case 'swapImages':
 
                    break;
                case 'swapImages':
 
                    imageView.image = 'images/match.png';
                    break;
 
            }
        });
        alertWindow.show();
    }
});
 
        tableview.setData(tableData);
 
    },
Could someone show me my error or some code that will allow me to select individual objects in the row.

Viewing all articles
Browse latest Browse all 8068

Trending Articles