[AC-1681] iOS: TableView insertRowAfter throws error on last index
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Cannot Reproduce |
Resolution Date | 2015-09-29T03:00:03.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | defect, ios, iphone |
Reporter | Dom Reilly |
Assignee | Shak Hossain |
Created | 2015-02-26T16:56:54.000+0000 |
Updated | 2016-03-08T07:38:10.000+0000 |
Description
Hi,
I've been having an issue with the code from https://gist.github.com/rileydutton/946647, which I have slightly modified, as shown below in the code.
Basically the code works fine, when you click parent 2, however if you do the following:
1) on app load click parent 2
2) click parent 1
3) then click parent 2 a few times
you are shown an error, stating: 'no row found for index'
I have also noticed that if you dismiss the message, a new row called with the title 'child' and a number(comes from the sub collection) is present, and the error is no longer thrown while this is shown.
Code:
--------------------------------------------------------------------------------------------------
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff'
});
var activeWindow = win1;
var layout = [{
title : "Parent 1",
_isParent : true,
_isOpen : false,
sub : [{
title : "Child 1"
}, {
title : "Child 2"
}]
}, {
title : "Parent 2",
_isParent : true,
_isOpen : false,
sub : [{
title : "Child 3"
}, {
title : "Child 4"
}]
}];
var tableView = Ti.UI.createTableView({
style : Titanium.UI.iPhone.TableViewStyle.GROUPED,
top : 0,
height : Ti.Platform.displayCaps.platformHeight,
data : layout
});
tableView.addEventListener("click", function(e) {
//Is this a parent cell?
if (e.row._isParent) {
// check to see if the row is open
if (e.row._isOpen) {
for (var i = e.row.sub.length; i > 0; i = i - 1) {
tableView.deleteRow(e.index + i);
}
e.row._isOpen = false;
} else {
// Add the children.
var currentIndex = e.index;
for (var i = 0; i < e.row.sub.length; i++) {
tableView.insertRowAfter(currentIndex, e.row.sub[i]);
currentIndex++;
}
e.row._isOpen = true;
}
}
});
activeWindow.add(tableView);
activeWindow.open();
Attachments
File | Date | Size |
---|---|---|
Screen Shot 2015-02-26 at 16.45.14.png | 2015-02-26T16:56:54.000+0000 | 67834 |
Hello, I have retested this issue with the latest environment and this is not a bug anymore. *Testing Environment:* Appcelerator Studio, build: 4.2.0.201508141038 Titanium SDK: 4.1.0 GA iOS simulator: iphone 5s(v8.1) OS X version: 10.9.5 *Test Case:* app.js
Thanks.