{ "id": "94474", "key": "TIMOB-9890", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "13503", "description": "Sprint 2012-14 Core", "name": "Sprint 2012-14 API", "archived": true, "released": true, "releaseDate": "2012-07-13" }, { "id": "13572", "description": "Release 2.1.1", "name": "Release 2.1.1", "archived": true, "released": true, "releaseDate": "2012-07-31" }, { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2012-08-02T09:27:42.000+0000", "created": "2012-07-05T14:23:43.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "SupportTeam", "api", "module_tableviewrow", "qe-testadded" ], "versions": [ { "id": "13271", "description": "Release 2.1.0", "name": "Release 2.1.0", "archived": false, "released": true, "releaseDate": "2012-06-29" } ], "issuelinks": [], "assignee": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2013-12-10T05:54:15.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "h3. Problem\r\n\r\nThe number of rows are not printed correctly on the console after removing rows from the tableview. \r\n\r\nPlease run the sample code below to reproduce the issue. We add rows using addRows() method and remove using removeRows() method providing the number of rows to be added or removed as arguments. It looks like the table data is manipulated asynchronously. \r\n\r\nThe workaround is to put a time interval wait for the table data changes to take effect. (Uncomment the passedTest() method to implement this workaround). \r\n\r\n*Note that you will see that the UI is updated, but the data[0].rows data structure is only updated after a delay*\r\n\r\nh3. Code Sample\r\n\r\n{noformat}\r\n\r\n\r\n// this sets the background color of the master UIView (when there are no windows/tab groups on it)\r\nTitanium.UI.setBackgroundColor('#000');\r\n\r\n\r\n//\r\n// create base UI tab and root window\r\n//\r\nvar win1 = Titanium.UI.createWindow({ \r\n title:'Tab 1',\r\n backgroundColor:'#fff'\r\n});\r\n\r\nvar table = Ti.UI.createTableView( {\r\n backgroundColor:'white',\r\n top: 0\r\n });\r\n\r\nwin1.add(table);\r\n\r\nwin1.open();\r\n\r\n//passedTest();\r\n\r\nfailedTest();\r\n\r\n\r\n/**\r\n * This test passes because we wait for the delete to complete before running the assertion\r\n */\r\nfunction passedTest() {\r\n \r\n Ti.API.info(\"Running passed test\");\r\n \r\n // add 1 row\r\n addRows(5);\r\n \r\n // should have 5 rows\r\n assertRowCount(5);\r\n \r\n // remove 1 row\r\n removeRows(1);\r\n \r\n // wait for the delete to complete - should have 4 rows\r\n waitForRowCount(4);\r\n \r\n Ti.API.info(\"Finishing passedHi Tim test\");\r\n}\r\n\r\n/**\r\n * This test fails because the delete is apparently asynchronous\r\n */\r\nfunction failedTest() {\r\n \r\n Ti.API.info(\"Running failed test\");\r\n \r\n // add 1 row\r\n addRows(5);\r\n \r\n // should have 5 rows\r\n assertRowCount(5);\r\n \r\n // remove 1 row\r\n removeRows(1);\r\n \r\n // should have 4 rows\r\n assertRowCount(4);\r\n \r\n Ti.API.info(\"Finishing failed test\");\r\n}\r\n\r\nfunction waitForRowCount(expectedCount) {\r\n var timer = setInterval(function () {\r\n if (table.data[0].rows && table.data[0].rows.length == expectedCount) {\r\n clearInterval(timer);\r\n assertRowCount(expectedCount);\r\n }\r\n }, 100); \r\n}\r\n\r\nfunction assertRowCount(expectedCount) {\r\n var actualCount = 0;\r\n if (table.data[0].rows) {\r\n actualCount = table.data[0].rows.length;\r\n }\r\n \r\n if (actualCount == expectedCount) {\r\n Ti.API.info(\"Row count is correct - expected: \"+expectedCount+\" found: \"+actualCount);\r\n } else {\r\n Ti.API.error(\"Row count is incorrect - expected: \"+expectedCount+\" found: \"+actualCount);\r\n }\r\n}\r\n\r\nfunction removeRows(count) {\r\n \r\n if (!table.data[0] || table.data[0].rows.rowCount < count) {\r\n return; \r\n }\r\n var tableData = table.data[0].rows;\r\n \r\n for (i=0;i