reordering tableViews

What is the proper way to reorder a tableView?

It seems complicated to try and figure out a sequence of deletes and inserts to rearrange a table, so it seems like it would make sense to just delete the table and rebuild it. That is what I’m trying to do, but my app keeps crashing (not in simulator, but on an ipad).
I am using a tableView widget and each row has a text string and an image. The images have tap events that need to move the row to a different part of the list.

When I detect a press, I’m calling
[lua]display.remove(myTableView)
myTableView = nil

–then I rebuild the table here[/lua]
Any suggestions of a better way to reorder the table, or any insight into why I’m getting crashes? The app doesn’t crash 100% of the time I touch one of the images, but proabbly pretty close to 80% of the time (and occasionally on mac simulator and never on windows simulator). I’m thinking it might have soemthing to do with the touch event handlers not getting cleaned up properly when the display.remove is called? Maybe?

This is with daily build 2012.786

[import]uid: 115687 topic_id: 25456 reply_id: 325456[/import]

When it crashes on the mac simulator what kind of error message appears? Also when you testing on your iPhone what error messages appear in the console window in Xcode?

In a slightly related topic, if all your trying to do is move to another part of the list you can use…

tableView:scrollToIndex( index, timeInMs ) [import]uid: 69826 topic_id: 25456 reply_id: 102868[/import]

Hey, thanks for the reply.
When my mac simulator crashes, I didn’t notice any messages in the terminal because the whole simulator program crashed (not just my app). Next time it happens I will store the log from the macOS crash window.

I just bought the mac (doing primary development on PC) and didn’t know that i could run my apps on my device and see error messages in the xcode console. I’ll look into how to do that tonight and see what it reveals.
Btw, I am not just trying to scroll to a part of the list, I’m trying to completely re-order the list (i.e. rows 1,2,3,4 -> rows 2,4,3,1 or something like that).

Asside from my crashing issues, is destroying and rebuilding a tableView the best way to completely reorder its rows?
[import]uid: 115687 topic_id: 25456 reply_id: 102921[/import]

Ok, problem solved.
Now instead of completely destroying the table object and rebuilding it, I’m just deleting all rows out of the table and then rebuilding it:

[lua]–delete all existing rows from my table
local rows = tview.content.rows
for i= #rows, 1, -1 do
tview:deleteRow(rows[i])
end
–insert all my data into the table with the new order
populate()[/lua]
This seems to work fine on my ipad now with no crashing.
Btw, I tried my old version with my ipad connected to the xcode terminal and I got “signal-11 segmentation fault”. [import]uid: 115687 topic_id: 25456 reply_id: 103004[/import]

Glad you got it working!

Its pretty strange thats its crashing each time you delete and remake the table. I do that all the time in one of the apps i’ve made and it works fine. My only guess is it wasn’t being removed correctly which was causing it to crash. But thats just a random guess :smiley:

Thanks for posting your method, I’m sure lots of people will find that helpful!
In regards to seeing output in xcode, you would need to have

 io.output():setvbuf('no') 

at the top of your main.lua file, then you can see all the prints() etc straight in Xcode. [import]uid: 69826 topic_id: 25456 reply_id: 103039[/import]