Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1970] TableViewRow hasCheck property not getting toggled on click event

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2013-07-16T22:53:52.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelshasCheck, ios, tableviewrow, toggle
Reporterankur garha
AssigneeCarter Lathrop
Created2013-07-16T12:55:59.000+0000
Updated2016-03-08T07:40:54.000+0000

Description

Try to toggle the hasCheck property of TableViewRow using click event but its not behaving properly as expected. I found it working properly in Android but not working in iOS Please find the sample code attached below.
 
function TestView() {   
    var data = [];
    var self = Titanium.UI.createTableView({        
        data : data,
    }); 
    for (i = 0; i < 5; i++) {
        var section = Titanium.UI.createTableViewSection({headerTitle: "section"+i});       
        for (j = 0; j < 5; j++) {
            var row = Ti.UI.createTableViewRow({
                title : "row"+j
            });
            section.add(row);            
        }
        self.appendSection(section)
    }
    self.addEventListener('click', function(e) {
        e.row.hasCheck = !e.row.hasCheck;
    });
    return self;
}
module.exports = TestView;
*Result* On clicking any table view row, it is unable to toggle a check mark on the right side of the row clicked *Expected* On clicking any table view row, it should toggle the check mark on the right side of the row clicked

Attachments

FileDateSize
iOS Simulator Screen shot 16-Jul-2013 6.36.34 PM.png2013-07-16T13:07:00.000+000018970

Comments

  1. Carter Lathrop 2013-07-16

    Hello Ankur, I did some research into your issue and have found the root of the problem as well as a solution for you. When I looked over the documents for appendSection()(http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.TableView-method-appendSection) I first noticed this warning in the page: "Due to a known issue, TIMOB-12616, this method should not be used for adding sections on iOS." This is probably the reason why this code is not working for you. Instead, I did some tinkering and came up with a solution for you. Instead of using appendSection(), I pushed the created sections into the data array and used setData() to set the sections into the table and everything worked perfectly for both Android and iOS. Here is the sample code I came up with:
       var win = Ti.UI.createWindow({
       	backgroundColor : 'white'
       });
       
       var data = [];
       var self = Titanium.UI.createTableView({
       });
       
       for ( i = 0; i < 5; i++) {
       	var section = Titanium.UI.createTableViewSection({
       		headerTitle : "section" + i
       	});
       	for ( j = 0; j < 5; j++) {
       		var row = Ti.UI.createTableViewRow({
       			title : "row" + j
       		});
       		section.add(row);
       	}
       	data.push(section);
       }
       self.setData(data);
       
       self.addEventListener('click', function(e) {
       	if (e.row.hasCheck) {
       		e.row.hasCheck = false;
       	} else {
       		e.row.hasCheck = true;
       	}
       });
       win.add(self);
       win.open();
       
    I am going to resolve this issue for now. If you have any further questions don't hesitate to ask. Best, Carter
  2. Shak Hossain 2013-12-28

    Since we have not heard from the reporter and a recommendation to fix the code has been posted, closing this.

JSON Source