Read text file into IOS table

I am working on a pre-flight check list app. I have a list of items (see sample below) that I want to load into a table (or somewhere, it doesn’t have to be a table) so I can use them within my app. Is there a way to read a text file into my table? I use to be a realbasic user and I know how to do this for a desktop app, but I am new to IOS programming, so if possible, talk to me like I am a newbie :slight_smile: thanks!

for example my text file might contain:

Preflight Inspection
**
Cabin
Aircraft Acceptance check
Control lock
Flight controls
Fuel Selector
Ignition switch
Parking brake
Aviaonics switch
Electrical Switches
Alternate static source
Battery Master Switch

Use just the same technique as Desktop :

If you need to exchange new documents, you can do that with the iTunes sharing.
https://forum.xojo.com/18037-how-to-get-database-into-out-of-ios-device

ok, that makes sense, but it doesn’t seem to be finding my txt file. I imported my text file c172pchecklist.txt into xojo and have it in the same folder as my xojo project.

I have a table called table1, and a button with the following code:

Dim f As FolderItem
  f = SpecialFolder.Documents.Child("c172pchecklist.txt")
  
  If Not f.Exists Then
    // Cannot read the file if it does not exist
    Label1.text="error"
    Return
  End If
  
  Table1.AddSection("Maintenance status") 
  
  Dim errorText As Text
  Try
    Dim input As TextInputStream
    input = TextInputStream.Open(f, TextEncoding.UTF8)
    Table1.AddRow(0, input.ReadLine)
    input.Close
  Catch e As IOException
    errorText = "File IO Error: " + e.Reason
  End Try

[quote=258784:@Michael Walach]ok, that makes sense, but it doesn’t seem to be finding my txt file. I imported my text file c172pchecklist.txt into xojo and have it in the same folder as my xojo project.

I have a table called table1, and a button with the following code:

[code]
Dim f As FolderItem
f = SpecialFolder.Documents.Child(“c172pchecklist.txt”)

If Not f.Exists Then
// Cannot read the file if it does not exist
Label1.text=“error”
Return
End If

Table1.AddSection(“Maintenance status”)

Dim errorText As Text
Try
Dim input As TextInputStream
input = TextInputStream.Open(f, TextEncoding.UTF8)
Table1.AddRow(0, input.ReadLine)
input.Close
Catch e As IOException
errorText = "File IO Error: " + e.Reason
End Try
[/code][/quote]

No no no. That won’t work in iOS. You definitely cannot place anything next to the executable.

Instead, drag the file into the project and do

f = SpecialFolder.GetResource("c172pchecklist.txt")

In iOS the SpecialFolder.Documents folder is in the container of the app, not your regular Documents folder . On a test app I just made, it is at

/Users/Mitch/Library/Developer/CoreSimulator/Devices/3605B3D6-EE94-4FAB-97CE-3B66415FA650/data/Containers/Data/Application/C4717F95-2AC8-44A6-9B5D-4B92E8E70E4A/Documents

It will be different in the sandboxed app on the device.

So if you do not need to edit the file, drag it into the project. Otherwise use CopyTo to place it in iOS Documents so it can be changed in iTunes sharing.

That you very much my friend! You have saved me many hours of frustration! Thank you!

One last question. Now that I have my data loaded into my table, I need to display it. I am trying to do something like this:

Label1.text=table1.RowData(0,1)

I am reading through the help guide, but can’t figure out the right syntax.

For loading files onto the iOS device, refer to this page:

http://developer.xojo.com/userguide/ios-copying-files-to-the-device

For displaying the row information, you are close. If you look at the doc page for iOSTable.RowData you’ll see that it returns a iOSTableCellData. Clicking that will show you its properties. There you’ll see the iOSTableCellData.Text property is what you want. So your code would be:

Label1.Text = Table1.RowData(0, 1).Text

Another way to do this is to read the text file into an array and then you have the data for however many times this table view gets displayed. I’m personally fond of creating an iOSDataTableSource class for each view and using those methods to create the table.

thanks guys, this is great!