iOS Question My iTableView challenges - Please advice...

Mashiane

Expert
Licensed User
Longtime User
Hi

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?

https://www.dropbox.com/s/2a0xyv9w2o1smtz/iBibleShow.zip?dl=0

This followed this approach here: https://www.b4x.com/android/forum/threads/multiple-pages-example.48170/#post-312440

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.
 

Erel

B4X founder
Staff member
Licensed User
Longtime 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.

On pg_resize event, is it compulsory / needed to .SetLayoutAnimated for iTableView?
It is important. Otherwise the table view size will not be correct.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime 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.
 
Upvote 0

Mashiane

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

B4X:
'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.Initialize("pg")
     pg.RootPanel.Color = Colors.White
     lstBD.Initialize("lstBD", False)
       pg.RootPanel.AddView(lstBD, 0, 5, 100%x, 95%y)
   End If
   Main.NavControl.ShowPage(pg)
   RefreshBD
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
   frmVerses.Show
End Sub
   
Sub RefreshBD()
   ''modBibleShow.OpenDb
   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...")
   lstBD.Clear
   'lstBD.BeginUpdates
   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)
   Loop
   'lstBD.EndUpdates
   cur.close
   'b4iMash.HideProgress
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.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Hi Erel, thanks for the help, I found a solution in one of the questions by accident just right now. All I had to do was iTableView.ReloadAll after reading my records from the SQLite table and loading them to the iTableView. All is perfect now.


See my answer in the other thread you started.[/QUOTE
 
Upvote 0
Top