iOS Question TableView If Then

kozbot

Member
Licensed User
Longtime User
So, I'm trying to do a if a list item is clicked, then change label2, but it's just not working... It works perfectly in b4a, but I think I'm missing something for b4i, plus I'm a noob, which isn't helpful. This is what I've got, and thanks in advance for your help!

B4X:
Sub Show
    pg.Initialize("pg")
    pg.RootPanel.LoadLayout("layout")
    TableView1.Initialize("TableView1", False)
       pg.RootPanel.AddView(TableView1, 0, 0, 100%x, 49%y)
    pg.RootPanel.Color = Colors.Black
   
    TableView1.SeparatorColor = Colors.Black
    TableView1.Color = Colors.Blue
   
    pg.Title = "5000 Trouble Shooting"
    Main.NavControl.ShowPage(pg)
        TableView1.AddSingleLine("Zone light on or long beeps on Arming.")
        TableView1.AddSingleLine("10 beeps upon Arming. Mains light flashing. Battery light flashing.")
        TableView1.AddSingleLine("10 Beeps at any time (mains / battery light flashing)")
        TableView1.AddSingleLine("1 long beep during keypad entry.")
        TableView1.AddSingleLine("Constant tone upon Arming.")
        TableView1.AddSingleLine("2 second siren at end of exit time.")
        TableView1.AddSingleLine("Constant tone on entering premises.")
        TableView1.AddSingleLine("External strobe light flashing.")
        TableView1.AddSingleLine("Siren sounding when system disarmed.")
        TableView1.AddSingleLine("Armed/monitor light flashing.")
        TableView1.AddSingleLine("Zone Excluded light flashing.")
        TableView1.AddSingleLine("Tamper light flashing.")
        TableView1.AddSingleLine("Alarm memory light flashing.")
End Sub
Sub TableView1_click
    Label2.TextColor = Colors.White
   
    Dim Rownumber As Int
    Dim tc As TableCell = TableView1.GetItems(0).Get(Rownumber)
   
       If Rownumber = 0 Then
        Label2.Text = "Zone detection device (eg.reed switch, movement detector) unsecured. Number of beeps determine which zone is unsecured. Close door or window. Find cause of movement."
    Else If Rownumber = 1 Then
        Label2.Text = "Mains power off. Battery low. Check plug pack is plugged in and power point on, or call Installation Company."
        Log("Clicked 1")
        Else If Rownumber = 2 Then
        Label2.Text = "Mains power off. Battery low. Check plug pack is plugged in and power point on, or call Installation Company."
        Else If Rownumber = 3 Then
        Label2.Text = "Invalid keypad entry.Press END button and re-enter."
        Else If Rownumber = 4 Then
        Label2.Text = "Tamper, panic or 24 hour inzone unsecured. Check panic button (If installed), or call Installation Company."
        Else If Rownumber = 5 Then
        Label2.Text = "Zone unsecured before expiry of exit time. Re-enter premises, disarm system, check zone isolate memory to determine zone."
        Else If Rownumber = 6 Then
        Label2.Text = "Alarm occurrence since last arming of panel. Check Alarm memory to determine zone at fault."
        Else If Rownumber = 7 Then
        Label2.Text = "Alarm occurrence since last arming of panel. Check Alarm memory to determine zone at fault."
        Else If Rownumber = 8 Then
        Label2.Text = "Tamper, panic or 24 hour zone activated. Reset alarm by entering code or activating key switch, check panic buttons (if installed), or call Installation Company."
        Else If Rownumber = 9 Then
        Label2.Text = "Monitor mode entered by mistake. Exit monitor mode."
        Else If Rownumber = 10 Then
        Label2.Text = "A zone has been excluded."
        Else If Rownumber = 11 Then
        Label2.Text = "Tamper unsecured. Call Installation Company."
        Else If Rownumber = 12 Then
        Label2.Text = "Alarm in memory. Check alarm memory to see cause of alarm."
    End If
End Sub
 

Alessandra Pellegri

Active Member
Licensed User
Longtime User
I think that you should do:

B4X:
Sub TableView1_SelectedChanged (SectionIndex As Int, Cell As TableCell)
Label2.TextColor = Colors.White
Dim Rownumber As Int = TableView1.GetItems(SectionIndex).IndexOf(Cell)
  If Rownumber = 0 Then
  Label2.Text = "Zone detection device (eg.reed switch, movement detector) unsecured. Number of beeps determine which zone is unsecured. Close door or window. Find cause of movement."
  Else If Rownumber = 1 Then
  Label2.Text = "Mains power off. Battery low. Check plug pack is plugged in and power point on, or call Installation Company."
  Log("Clicked 1")
  Else If Rownumber = 2 Then
  Label2.Text = "Mains power off. Battery low. Check plug pack is plugged in and power point on, or call Installation Company."
  Else If Rownumber = 3 Then
  Label2.Text = "Invalid keypad entry.Press END button and re-enter."
  Else If Rownumber = 4 Then
  Label2.Text = "Tamper, panic or 24 hour inzone unsecured. Check panic button (If installed), or call Installation Company."
  Else If Rownumber = 5 Then
  Label2.Text = "Zone unsecured before expiry of exit time. Re-enter premises, disarm system, check zone isolate memory to determine zone."
  Else If Rownumber = 6 Then
  Label2.Text = "Alarm occurrence since last arming of panel. Check Alarm memory to determine zone at fault."
  Else If Rownumber = 7 Then
  Label2.Text = "Alarm occurrence since last arming of panel. Check Alarm memory to determine zone at fault."
  Else If Rownumber = 8 Then
  Label2.Text = "Tamper, panic or 24 hour zone activated. Reset alarm by entering code or activating key switch, check panic buttons (if installed), or call Installation Company."
  Else If Rownumber = 9 Then
  Label2.Text = "Monitor mode entered by mistake. Exit monitor mode."
  Else If Rownumber = 10 Then
  Label2.Text = "A zone has been excluded."
  Else If Rownumber = 11 Then
  Label2.Text = "Tamper unsecured. Call Installation Company."
  Else If Rownumber = 12 Then
  Label2.Text = "Alarm in memory. Check alarm memory to see cause of alarm."
  End If
End Sub
 
Upvote 0

kozbot

Member
Licensed User
Longtime User
OH MAN!!! I could've sworn I'd tried that!!!

Thanks so much for your help!!!!

UGH I'm such a noob... **shakes head in sorrow**
 
Upvote 0
Top