I have a newTableView control that has rows inserted and deleted based upon selection by the user. Nothing unusual there. The “selected” or last touched row has an icon that says “On” all other rows have one that says “Off”. Data in the system is configured based upon which row is On or Off. For the sake of argument, lets say that all rows are visible to eliminate rendering issues.
deleting rows 2-n allows me to use newTableView:getRowAtIndex(1) to turn row 1 “On” as the “touched” row. no problems there.
deleting row 1 has the problem. using newTableView:getRowAtIndex(1) now returns nil. Ok, that makes sense since I just deleted it. I originally thought that we have a threading issue that a performWithDelay would solve, but no such luck. After the delete, a file is downloaded that can take as much as 30 seconds. I dont call getRowAtIndex until the downloaded file has been finished and unzipped, so I dont believe it is a timing problem. I rigged a loop that walked the newTableView and testing for nil, and found that the index of the deleted row properly read as nil, and the next rows showed their indexes AS BEFORE THE DELETE. There is the key. I had understood that the indexes go re-indexed at some point. I cant seem to figure out when and how.
the simple answer is if getRowAtIndex(1) returns a nil, then use getRowAtIndex(2). duh. However if multiple rows are deleted before the control re-indexes, then how do we get the index of the topmost row.
now to add some complexity, if the “top” row has scrolled off the screen - its derendered and also returns nil.
I’ve tried scrollToIndex(1,100,onComplete) to force it to the top, but all calls to scrollToIndex, regardless of index crash within the api. I’ve reported this as a bug.
I figured that the scrollToIndex would force a re-render, and hopefully, a re-index and therefore getRowAtIndex(1) would work.
Is there any way to accomplish at newTextView:getTopVisibleRow() that returns the index of the top visible row?