[TIMOB-9973] iOS: Incorrect properties returned by TableView's longpress event.
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Medium |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2012-08-13T09:45:12.000+0000 |
| Affected Version/s | Release 3.0.0 |
| Fix Version/s | Sprint 2012-15 API, Release 3.0.0 |
| Components | iOS |
| Labels | api, module_tableview, parity, qe-testadded |
| Reporter | Hieu Pham |
| Assignee | Vishal Duggal |
| Created | 2012-07-16T15:05:21.000+0000 |
| Updated | 2012-12-27T18:41:43.000+0000 |
Description
Steps to reproduce:
1. Run this code:
var win = Ti.UI.createWindow();
var tableData = []
var s = 0;
var nRow = 0;
for(var i = 0; i < 100; i++){
var createNewSection = (i + 1) % 10 == 9 || i == 0 ? true : false;
createNewSection ? nRow = 1 : nRow++;
tableData.push({
title:'Row #' + nRow + ' Index #' + i + ' Section #' + s,
customProp:'Hello World! #' + i,
header: createNewSection ? 'Section #' + s++ : null
});
}
var table = Ti.UI.createTableView({
data: tableData
});
win.add(table);
table.addEventListener('longpress', function(e){
Ti.API.info('Section: ' + e.section);
if(e.row)
{
Ti.API.info('Row: ' + e.row);
Ti.API.info('Row Data: ' + e.rowData);
Ti.API.info('Index: ' + e.index);
Ti.API.info('customProp: ' + e.rowData.customProp);
}
});
win.open();
2. Perform a long press on multiple sections. You will see:
[INFO] Section: [object TiUITableViewSection]
[INFO] Row: [object TiUITableViewRow]
[INFO] Row Data: [object TiUITableViewRow]
[INFO] Index: 0
[INFO] customProp: Hello World! #0
printed for each and every section, which is inccorect. Row and all its data should be null if longpress is performed on a table section.
Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/2597
Ok so here is an example that shows how slow it gets. - it s already not so smooth on 2.1.0.GA but still very "scrollable" - it s drastically slower on 2.2.0 (master) - you wont see it on simulator!!! the problem appears on device (mine is an iphone 4).
var win = Ti.UI.createWindow(); function createRow(c) { var row = Ti.UI.createTableViewRow(); row.selectedBackgroundColor = '#fff'; row.height = 100; row.className = 'datarow'; row.clickName = 'row'; var photo = Ti.UI.createView({ backgroundImage:'user.png', top:5, left:10, width:50, height:50, clickName:'photo' }); row.add(photo); var user = Ti.UI.createLabel({ color:'#576996', font:{fontSize:16,fontWeight:'bold', fontFamily:'Arial'}, left:70, top:2, height:30, width:200, clickName:'user', text:'Fred Smith '+c }); row.filter = user.text; row.add(user); var fontSize = 16; if (Titanium.Platform.name == 'android') { fontSize = 14; } var comment = Ti.UI.createLabel({ color:'#222', font:{fontSize:fontSize,fontWeight:'normal', fontFamily:'Arial'}, left:70, top:21, height:50, width:200, clickName:'comment', text:'Got some fresh fruit, conducted some business, took a nap' }); row.add(comment); var calendar = Ti.UI.createView({ backgroundImage:'/KS_nav_ui.png', bottom:2, left:70, width:32, clickName:'calendar', height:32 }); row.add(calendar); var button = Ti.UI.createView({ backgroundImage:'KS_nav_views.png', top:35, right:5, width:36, clickName:'button', height:34 }); row.add(button); var date = Ti.UI.createLabel({ color:'#999', font:{fontSize:13,fontWeight:'normal', fontFamily:'Arial'}, left:105, bottom:5, height:20, width:100, clickName:'date', text:'posted on 3/11' }); row.add(date); var toolbar = Ti.UI.createView ({ bottom:0, right:0, height:38, width:200, backgroundColor:'#55000000', visible:false }); var decale = 0; for (var i=0;i<6;i++) { var button = Ti.UI.createButton({ right:decale, image:'KS_nav_views.png', width:38 }); toolbar.add(button); decale += 40; } row.add(toolbar); row.showToolbar = function() { toolbar.startLayout(); toolbar.visible = true; toolbar.finishLayout(); } row.hideToolbar = function() { toolbar.startLayout(); toolbar.visible = false; toolbar.finishLayout(); } row.switchToolbar = function(){ toolbar.startLayout(); toolbar.visible = !toolbar.visible; toolbar.finishLayout(); } return row; } var data = []; var lastRow = 150; for (var c=0;c<lastRow;c++) { var row = createRow(c); data.push(row); } var tableView = Ti.UI.createTableView({ data: data }); tableView.addEventListener('click', function(_event){ _event.row.switchToolbar(); }); win.add(tableView); win.open();Tested with Titanium SDK: 2.2.0.v20120808154112 Tested with Titanium Studio: 2.1.1.201207271312 On LongPress of Section header, exception is thrown in the logs as follows: [INFO] Section: [object TiUITableViewSection] [INFO] Row: undefined [INFO] Row Data: undefined [INFO] Index: undefined [WARN] Exception in event callback. { line = 27; message = "'undefined' is not an object (evaluating 'e.rowData.customProp')"; name = TypeError; sourceId = 252762528; sourceURL = "file://localhost/Users/nehachhabra/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/65094C8E-EFE7-4EBF-BE85-939A31265761/Test.app/app.js"; }
The test case is incorrect. Have updated the test case
Verified fixed with: Titanium Studio, build: 2.1.1.201207271312 SDK version: 2.2.0.v20120816015712 Devices: iPad3 4G (5.1.1) iPhone4s (5.0.1)