iOS Question My iTableView challenges - Please advice...


Licensed User

I am struggling with the iTableView a lot and kindly need some advice. I have defined my pages in code modules...

1. Where is the best location to initialize an iTableView? Inside pg.IsInitialized or outside? If outside, is that after navControl.ShowPage in your Show sub or just before?
2. What is the best location to load items to the iTableView, in your Show sub? pg_resize, pg_appear? or somewhere else?
3. On pg_resize event, is it compulsory / needed to .SetLayoutAnimated for iTableView? Can this event be left out when it comes to iTableViews or not?

Here is my troublesome source code, can someone please advise?

This followed this approach here:

With my code, I have initialized my listviews inside pg.IsInitialized, when I call my show method for the page concerned, the first time the lists are loaded properly. After I click the back button and open the same page from the listview the items dont show on the iTableView anymore.


Licensed User
Are the lists static? Or do you need to update the items dynamically?

If the data is static then fill the list once when pg.IsInitialized is false.

It is important. Otherwise the table view size will not be correct.
A: 1 of the lists needs to be dynamic and the rest static. How do I refresh that one?

There is a master iTableView where a user selects an entry and that opens another page with a listview. The first time this works fine, subsequent Show methods dont load the items in the iTableViews.


Licensed User
The page is initialized once. If you load the items only when pg.IsInitialized is false then the items will be loaded once.
'Code module

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Private pg As Page
   Private lstBD As TableView
End Sub

Sub pg_Appear
   Main.NavControl.ToolBarVisible = False
End Sub

Public Sub Show
   modBibleShow.strFrom = "bd"
   If frmVerses.aloud.IsInitialized = True Then frmVerses.aloud.stop
   Main.NavControl.ToolBarVisible = False
   If pg.IsInitialized = False Then
     pg.RootPanel.Color = Colors.White
     lstBD.Initialize("lstBD", False)
       pg.RootPanel.AddView(lstBD, 0, 5, 100%x, 95%y)
   End If
End Sub

Private Sub pg_Resize(Width As Int, Height As Int)
  lstBD.SetLayoutAnimated(500, 0.6, 0, 0, 100%x, 95%y)
End Sub

Sub lstBD_SelectedChanged (SectionIndex As Int, Cell As TableCell)
   ' lets open a dictionary item
   Dim sKey As String
   sKey = "Bible Dictionary_" & Cell.tag
   iStateManager.SetSetting("promise", sKey)
   modBibleShow.EachChapter = False
   modBibleShow.strFrom = "dictionary"
   modBibleShow.strPromise = Cell.tag
End Sub
Sub RefreshBD()
   Dim sKey As String = iStateManager.GetSetting("dictionary")
   Dim dMap As Map = b4iMash.Table_ReadToMap(modBibleShow.SQLite,"BibleDictionary","Key",sKey)
   Dim sText As String = dMap.Get("text")
   pg.Title = "Bible Dictionary - " & sText
   'b4iMash.ShowProgress("Loading bible dictionary...")
   Dim cur As ResultSet
   cur = b4iMash.Table_OpenRecordset(modBibleShow.SQLite, "select [Key],Text from BibleDictionary where Parent = '" & sKey & "' order by Text")
   Do While cur.NextRow
     Dim sKey As String: sKey = cur.GetString("Key")
     Dim sText As String: sText = cur.GetString("Text")
     b4iMash.AddSingleLine2(lstBD, sText, sKey)
End Sub
This is an approach I have followed for most of the code in my page modules. The contents of the iTableView in all except 1 are static. This works on the initial Show sub when accessing it from another page. When I call Show again by clicking an iTableView item from the master dynamic iTableView, the items are not loaded for this module. The first post has a link to the source of this project. Can you please advise what I'm missing? Thanks.