How to implement a searchField iOSMobileTable

Since 2.0 you can add a search field to an iOSMobileTable, but I can’t find anywhere info how to implement.
Can somebody give me a hint?

Just activate AllowSearch in iOSMobileTable ans add SearchChanged-Event.
https://documentation.xojo.com/api/ios/iosmobiletable.html#iosmobiletable-allowsearch
https://documentation.xojo.com/api/ios/iosmobiletable.html#iosmobiletable-searchchanged

I did, but nothing happens

Turn the AllowSearch property to ON (True).

Pull down on the table in a running app to display the search field. The SearchChanged event is called when text is entered into the field.

Does it work with mobileTableCustomCell?

It works with the table. It doesn’t matter how you’ve populated the table.

If you create a new project it is working.
If you add a iOSMobileTable to an existing (before 2.0) project, it is not working.
It is like the Timer problem.

You may need to put it on an iOSLayout for it to work as it interacts with the view.

I don’t follow you.
I have to change the super of an iOSScreen into iOSLayout?

Well, I don’t get it. Once I add the “SeachChanged” event, what do I put in it? EXAMPLES?

The SearchChanged event is fired when the user types into the search field. Use the passed string to narrow down the data you show. For example if you were making a phone contact directory you could refresh the table to only show names that start with the passed string.

1 Like

For a directory, I have an array of People, which is a class that has a FullName field. I also have a String array called PeopleSearchResult. The table doesn’t display People, it displays PeopleSearchResult.

In the table Opening event I have:

Sub Opening() Handles Opening
  Directoryds = New DirectoryDataSource
  Me.DataSource = Directoryds
  
  Me.SetSearchFilters = Array("Full Name", "First Name", "Last Name")
  
  // Rebuild People array
  PeopleSearchResult.RemoveAll
  If People.LastIndex <> -1 Then 'array is populated
    For i As Integer = 0 To People.LastIndex
      PeopleSearchResult.Add(People(i).FullName)
    Next
  End If
End Sub

In the table SearchChanged event I use:

Sub SearchChanged(value as String) Handles SearchChanged
  // Rebuild People array
  PeopleSearchResult.RemoveAll
  
  If People.LastIndex <> -1 Then 'array is populated
    For i As Integer = 0 To People.LastIndex
      Select Case Me.GetSearchFilterIndex()
      Case 0
        If People(i).FullName.IndexOf(value) > -1 Then
          PeopleSearchResult.Add(People(i).FullName)
        End If
        
      Case 1
        If People(i).FullName.NthField(" ",1).IndexOf(value) > -1 Then
          PeopleSearchResult.Add(People(i).FullName)
        End If
        
      Case 2
        If People(i).FullName.LastField(" ").IndexOf(value) > -1 Then
          PeopleSearchResult.Add(People(i).FullName)
        End If
        
      End Select
    Next
  End If
  
  // Show current hits
  Me.ReloadDataSource
End Sub