I’m having one issue regarding to removing selected row from table using data source.
Workflow is goes as follow:
User select Delete option item from Row Action when he swiped from right to left of the screen.
Code checks if Delete action index is selected and if it does then ask user via message box ‘Are you sure to delete…’ - Yes/No
Handler to this message box event is added
In handler later I’m checking if user selected YES and trying to execute this code to remove row after record is deleted from database.
I’m getting error (bug) when Xojo try to execute MyTable.RemoveRow(Section,Row).
Notes: I captured Section and Row values and hold them in local (private) properties of view where table is, so later I can use them.
This means that right call then is MyTable.RemoveRow(LastSection,LastRow) from handler function if user click on YES in MessageBox.
I’m getting in debug window:
Reason: Invalid update: invalid number of rows in section.
I set ‘Return True’ in RowIsEditable method which comes as interface part of iOSTableDataSourceEditing
If you’re using an iOSTableDataSource to populate the iOSTable, then you need to delete the row from the underlying data source, not from the table itself, and then call ReloadData or ReloadDataInSection to refresh the table display. In other words, if you didn’t populate the table with AddRow then you don’t delete rows with RemoveRow instead use RowData, SectionCount and the other iOSTableDataSource interface methods to populate the table.
Hello Jason Tait,
Thanks for your reply.
Anyway I found by my self some kind of solution and hope that is right one.
Solution concept is:
Remove record from database then
Remove record from datasource array e.g. mydatasections(lastsection).myrows.remove(lastrow) then
Remove row from table by calling mytable.RemoveRow(lastsection,lastrow)
So with this I don’t need to reload all data or only to reload data in that section.
What you think (I’m asking you this since Xojo is new to me) ?
In a recent app I made I ended up inserting / deleting the wrong rows in the database just because I was holding section and row values for each row.
I would recommend to assign a tag to each row and when the user deletes the row, search for the correct row in a loop using the tag.
It might be a little more CPU intensive but worth the error-proofing.
Set the TABLE Unique ID in the Listbox Row tag, then use this value to delete the Record from the DB.
Thanks for reply.
Yea I’m using tag in which I’m holding complete instance of object class which is related to record in db.
When I get selected row, I just extract tag as object class instance and fire e.g. DeleteRecord() method of it
If that is done well then I’m removing row from table and do other GUI stuff.
Since I already have section id and row id I don’t have to go over all sections and rows to check tag for value and match to it (I think).
I’m planning after I complete and wire up all what I need to switch from assigning instance of class to tag with a just placing Db RecordID in tag property since I think it will reduce memory usage since ID would be a string or integer which takes less memory then class object
For know it’s just testing and to see how everything will come together and see what I can do with Xojo (from limits point of view).
I’m (just) a new to Xojo dev.
That’s exactly what I do not recommend
It is safer to go through the entire table again and compare each row’s ID to match with the removed row.
Hmm that is interesting.
Are you sure that there are issues regarding to it?
Is there any chance that maybe on your end you didn’t do something well or maybe some other events are also triggered in your app and makes this things to happen?
For now I’m just doing delete process using Action button per row (swipe from right to left and when user tap on DELETE button).