iOS Question iTableView Custom Cell Problem

RichardN

Well-Known Member
Licensed User
Longtime User
An iTableView has identical custom cells. Each cell is loaded with the same layout containing two labels. I wish to retrieve the second label text when the cell is clicked.

The 'sender' object returned in the TableView1_SelectedChanged event always seems to be an iTableView despite clicking on a label.

How is this done? I am sure I am missing something really simple here?


B4X:
Private Sub CreateItem (index As Int) As Panel
    
    Dim p As Panel
    p.Initialize("")
    p.Width = 100%x
    p.Color = Colors.Black
    p.Height = TableView1.RowHeight
    p.LoadLayout("ecam_cell")
   
    lblECAM.Text = Warnings.GetString("ECAM_Warning")
    lblSystem.Text = Warnings.GetString("System")
    p.Tag = lblSystem.Text
    Return p
   
End Sub

Sub TableView1_SelectedChanged (SectionIndex As Int, Cell As TableCell)

   Dim lbl As Label = Sender
   Dim no As NativeObject = lbl
   Dim Parent As Panel = no.GetField("superview") 'get the label's parent
   Dim FindSys As String = Parent.Tag

   Log(FindSys)

End Sub
 

RichardN

Well-Known Member
Licensed User
Longtime User
Solved: The NativeObject/Superview method is not appropriate in this context. Using the Click event on the panel instead of the TableView_SelectedChanged event is much simpler.

B4X:
Private Sub CreateItem (index As Int) As Panel
   
    Dim p As Panel
    p.Initialize("CustomPanel")
    p.Width = 100%x
    p.Color = Colors.Black
    p.Height = TableView1.RowHeight
    p.LoadLayout("ecam_cell")
  
    lblECAM.Text = Warnings.GetString("ECAM_Warning")
    lblSystem.Text = Warnings.GetString("System")
    p.Tag = lblSystem.Text
    Return p
  
End Sub

Sub CustomPanel_Click
   
   Dim pnl As Panel = Sender
   Dim FindSystem As String = pnl.Tag

   Log(FindSystem)
   
End Sub
 
Upvote 0
Top