SelectRow not Working on iOSMobileTable

I’ve been having pretty good luck with iOS development using Xojo but there is one thing that is really hanging me up. SelectedRow doesn’t seem to be working on an iOSMobileTable in my app (or more likely, I’m doing it wrong). It seems easy enough:

theTable.SelectRow(0, theRow)

Nothing happens. :-\ I tried putting it in the table object [me.SelectRow(0, theRow)], in the parent screen object, even the app object. No change.

I also tried this after the SelectRow:

theTable.Refresh

And even this:

theTable.ReloadRow(0, theRow)

And I tried the refresh both before and after the SelectRow call.

No errors, just no selection apparent. Same behavior in the iPad simulator and on a real iPad Pro. What am I missing?

Xojo 2023 R2, Xcode 14.2, Mac OS Monterey 12.6.5, MacBook Pro 16" M1 Max

I placed the following code in the Table’s Opening event and it works.


for i as Integer = 0 to 10
  me.AddRow i.ToString
  
next

me.SelectRow(0, 2)

Are you using a datasource? CustomCells?

Thanks for the reply, Jeremie. I have a second screen that is displayed with

screen2.show(self)

When screen2 is deactivated to return to the original screen, the table, which is on the original screen, has forgotten its selection. I was trying to use SelectRow on the deactivate event for screen2 to re-select the row that was originally selected. I have also tried adding it to screen1’s activate event, too, but neither seems to do the job. Stepping through the code I can see that it does hit SelectRow call but…nothing.

As the app is in the early development stages, the list just has some test data in it that is all added with AddRow. No custom cells.

I have another app that just adds some rows to a table and does SelectRow(0, 0) in the Opening event and that one does work. Puzzling…

When screen2 is deactivated, you are in some sort of race condition. The row is selected but then the table is refreshed by the system and lose the selection.

This might work:

  • Add two properties to Screen1: selectedSection and selectedRow (default values=-1)
  • Change the value of these properties when a row is tapped (Table.SelectionChanged event)
  • Add a method in Screen1: ReselectRow
if selectedSection > -1 and selectedRow > -1 then
  Table1.SelectRow(selectedSection, selectedRow)
End if
  • In Screen1.Activated event:
Timer.CallLater(20, AddressOf ReselectRow) //Will call ReselectRow in 20 miliseconds

That’s as good an hypothesis as any I’ve been able to come up with. :slight_smile:
I’ll give it try, probably tomorrow.

Thank you again!

You are a genius, Jeremie, that works like a charm! Thank you so much!

1 Like