iOS Question Problem with TableView

karyadi

Member
Licensed User
Longtime User
Hi All,

i make ios app using tableview as listview,
when i use example from erel https://www.b4x.com/android/forum/threads/tableview-b4i-listview.50403/
every thing run good,
but when i move
B4X:
   For i = 1 To 50
     TableView1.AddSingleLine("Item #" & i)
 
     'create an item and customize it
     Dim tc As TableCell = TableView1.AddTwoLines("First line", "") 'the second line will be soon added
     tc.Bitmap = img
     tc.IndentationLevel = Rnd(0, 5)
     Dim ColoredTitle As AttributedString
     ColoredTitle.Initialize("Second line", Font.CreateNew(19), Rnd(0x80000000, -1))
     tc.DetailText = ColoredTitle
   Next
into Sub JobDone(Job As HttpJob), the list not show.
what is the problem??

here is i attach my code
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 menu4a As Page
    Private TableView1 As TableView
    Private STATUS = "STATUS"
    Private CARIDATA = "CARIDATA"
    Private LIHATDATA = "LIHATDATA"
    Private INSERT1 = "INSERT1"
    Private INSERT2 = "INSERT2"
    Private hd As HUD   
    Private ImageView3 As ImageView
    Private nomor As Int
    Dim    tanggal,nama_event,admin As String
    Dim foto, foto1 As Bitmap
    Dim img1 As Bitmap

End Sub

Public Sub Show
    If menu4a.IsInitialized = False Then
        menu4a.Initialize("menu4a")
        If Main.TypeDevice = "iPhone" Then   
            menu4a.RootPanel.LoadLayout("menu4")
        Else
            menu4a.RootPanel.LoadLayout("menu4_ipad")
        End If
    End If
    Main.NavControl.ShowPage(menu4a)
       TableView1.Initialize("TableView1", False)
    menu4a.RootPanel.AddView(TableView1, 5%x, 25%y, 80%x, 60%y)
    img1 = LoadBitmap(File.DirAssets, "merc1.png")
'   For i = 1 To 50
 
     'create an item and customize it
'     Dim tc As TableCell = TableView1.AddTwoLines("First line", "") 'the second line will be soon added
'     tc.Bitmap = img
'     tc.IndentationLevel = Rnd(0, 5)
'     Dim ColoredTitle As AttributedString
'     ColoredTitle.Initialize("Second line", Font.CreateNew(19), Rnd(0x80000000, -1))
'     tc.DetailText = ColoredTitle
'   Next
      
    hd.ProgressDialogShow("Checking Event")
    ExecuteRemoteQuery("Select nomor,nama_event,tgl_event,foto from event_info where tgl_event > DATE_SUB(NOW(), INTERVAL 7 DAY) and area='"& Main.AREA &"' and status_event=0" , STATUS)

'  For i = 1 To 50
'    TableView1.AddSingleLine("Item #" & i)
'
'    'create an item and customize it
'    Dim tc As TableCell = TableView1.AddTwoLines("First line", "") 'the second line will be soon added
'    tc.Bitmap = img1
'    tc.IndentationLevel = Rnd(0, 5)
'    Dim ColoredTitle As AttributedString
'    ColoredTitle.Initialize("Second line", Font.CreateNew(19), Rnd(0x80000000, -1))
'    tc.DetailText = ColoredTitle
'  Next   
 
End Sub

Sub TableView1_SelectedChanged (SectionIndex As Int, Cell As TableCell)
    Log(Cell.Tag)
    nomor = Cell.Tag
    ExecuteRemoteQuery("SELECT tgl_event, foto FROM event_info_agent WHERE nomor_event_info = "& Cell.Tag &"", CARIDATA)
End Sub

Sub Base64StringToImage(s As String) As Bitmap
   Dim su As StringUtils
   Dim bytes() As Byte = su.DecodeBase64(s)
   Dim In As InputStream
   In.InitializeFromBytesArray(bytes, 0, bytes.Length)
   Dim bmp As Bitmap
   bmp.Initialize2(In)
   In.Close
   Return bmp
End Sub

Sub ImageToBase64(img As Bitmap) As String
   Dim su As StringUtils
   Dim out As OutputStream
   out.InitializeToBytesArray(0)
   img.WriteToStream(out, 100, "JPEG")
   Return su.EncodeBase64(out.ToBytesArray)
End Sub

Sub ExecuteRemoteQuery(query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://www.astacomputer.com/countries.php", query)
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success Then
    Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
        Select Job.JobName
            Case STATUS               
                Dim USERINFO As List
                USERINFO = parser.NextArray 'returns a list with maps
                For i = 0 To USERINFO.Size - 1
                    Dim m As Map
                    m = USERINFO.Get(i)
                    TableView1.AddSingleLine (i)
                    Log(i)
'                    Dim tc As TableCell = TableView1.AddTwoLines("", "") 'the second line will be soon added
'                    tc.Bitmap = Base64StringToImage(m.Get("foto"))
'                    tc.Tag = m.Get("nomor")
'                    tc.Text.Initialize(m.Get("nama_event"),  Font.CreateNew(14), Colors.Red)
'                    Dim ColoredTitle As AttributedString
'                    ColoredTitle.Initialize(m.Get("tgl_event"), Font.CreateNew(14), Colors.Black)
'                    tc.DetailText = ColoredTitle
                Next
               

               
                hd.ProgressDialogHide
               
            Case CARIDATA
                Dim USERINFO As List
                USERINFO = parser.NextArray 'returns a list with maps
                If USERINFO.Size > 0 Then
                    For i = 0 To USERINFO.Size - 1
                        Dim m As Map
                        m = USERINFO.Get(i)
                        foto = Base64StringToImage(m.Get("foto"))
                    Next
                    ImageView3.Bitmap = foto
                    ImageView3.Top = 0
                    ImageView3.Left = 0
                    ImageView3.Width = 100%x
                    ImageView3.Height = 100%y
                    ImageView3.Visible = True           
                    hd.ProgressDialogHide
                Else
                    ExecuteRemoteQuery("SELECT nama_event,tgl_event,admin, foto FROM event_info WHERE nomor = "& nomor &"", LIHATDATA)
                End If
               
            Case LIHATDATA
                Dim USERINFO As List
                USERINFO = parser.NextArray 'returns a list with maps
                For i = 0 To USERINFO.Size - 1
                    Dim m As Map
                    m = USERINFO.Get(i)
                    tanggal = m.Get("tgl_event")
                    nama_event  = m.Get("nama_event")
                    foto1 = Base64StringToImage(m.Get("foto"))
                    admin = m.Get("admin")
                Next
                ExecuteRemoteQuery("INSERT INTO event_info_agent (tgl_event, nama_event, foto, admin, area, agent, nilai, nomor_event_info) VALUE ('"& tanggal &"', '"& nama_event &"', '"& ImageToBase64(foto1) &"', '"& admin &"', '"& Main.AREA &"', '"& Main.USERNAME &"', 0, "& nomor &")" , INSERT1)

            Case INSERT1
                ExecuteRemoteQuery("INSERT into notification (username, area, waktu, kegiatan, menu) values ('"& Main.USERNAME &"','"& Main.AREA &"',NOW(),'Upload Event Inside','menu4')" , INSERT2)

            Case INSERT2
                ImageView3.Bitmap = foto1
                ImageView3.Top = 0
                ImageView3.Left = 0
                ImageView3.Width = 100%x
                ImageView3.Height = 100%y
                ImageView3.Visible = True
                hd.ProgressDialogHide
               
        End Select
    Else
        hd.ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Sub ImageView2_Click
    page.Show

End Sub


Please help me.

thanks
 
Top