iOS Question A Rich String Formatting For The TableView

Discussion in 'iOS Questions' started by RichardN, Jun 8, 2015.

  1. RichardN

    RichardN Active Member Licensed User

    I am having great difficulty in utilising the RichString class to format a string to add to the TableView.

    The code appears simple enough but the class appears to return a (label) object where the TableView is expecting a string. I simply wish to pass a series of rich strings as a single line to the TableView formatted for UL & colour.

    What is the simplest way of coding this ?
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can get the AttributedString with RichString.AttributedString.
  3. RichardN

    RichardN Active Member Licensed User

    Thanks Erel. Sorry to be a pain but there is something fundamental I am missing here relating to the Richstring Class.

    Returning the RichString.AttributedString method from a subroutine is still giving a warning #7.... 'Object converted to string. This is probably a programming mistake'

    I have the RichString Class module loaded and all the methods are correctly exposed in the main module. The code looks something like this:

    Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private MyResultSet as SQL
    Private TableView1 As TableView
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
        NavControl = Nav
        Page1.Title = 
    "My Table List"
        Page1.RootPanel.Color = 

        MyResultSet = 
    SQL.ExecQuery("SELECT * FROM MyTable ORDER BY MyField")
        NavControl.NavigationBarVisible = 
    Dim MyRecord as string

    Do While MyResultSet.NextRow
              MyRecord = MyResultSet.GetString(
    End Sub

    Sub RsFormat(subject As StringAs RichString

    Dim rs As RichString
    Dim l As Int = subject.Length -1
    Colors.Black , 0, l)
    Colors.Green , 0, l)

    Return rs.AttributedString                       'Returning wrong type of Object ?

    End Sub

    Where am I going wrong here ?
    Last edited: Jun 9, 2015
  4. Erel

    Erel Administrator Staff Member Licensed User

    TableView.AddSingleLine expects a string. It will not work with AttributedString. Instead you should do:
    Dim tc As TableCell = TableView1.AddSingleLine("")
    tc.Text = 
    'attributedstring here
  5. RichardN

    RichardN Active Member Licensed User

    Thanks Erel I get the difference now. Given that many of us are going back to school with B4i the difference between RichString and AttributedString needs to be understood.

    Having made that step I have encountered further limitations. I am trying to construct a two-line ListView TableView that has many major items each with a minor item below. On the face of it the stock TableView looks good using:

    TableView1.AddTwoLines ("Major Item","Minor Item")
    Unfortunately for user consistency I need an overall black background with green text and partial underlining for the major line and plain white text for the minor item. Like this.....


    It seems the only way to achieve this flexibility is to create a single line TableView with CustomView Cells each with 2 labels inside a parent panel. The labels are made in different font sizes and WILL accept both plain text and AttributedText.

    Unfortunately when I run the program loading ~100 database strings... ***only the last loaded cell appears on the TableView***. Any idea why this might be ?

    Do While Warnings.NextRow
    Dim tCell As TableCell = TableView1.AddSingleLine("")
          tCell.ShowSelection = 
          tCell.CustomView = CreateItem(TableView1,Warnings.GetString(
    "Warning"), Warnings.GetString("System"))

    Private Sub CreateItem(tvTableView As TableView, TopLine As String, BottomLine As StringAs Panel

    Dim lblWarning, lblSystem  As Label

        lblWarning.Font = 
    Dim rs As RichString
    True, ,0,uLine(TopLine))          'Underline length varies with subject
        lblSystem.Font = 
        lblSystem.Color = 
        lblSystem.TextColor = 
        lblSystem.Text = BottomLine                                
    'No text formatting here
    Dim HalfHeight As Int = tvTableView.RowHeight/2
    End Sub
  6. RichardN

    RichardN Active Member Licensed User

    To Answer my own question.....

    The panel 'ParentPanel' was defined in Process_Globals. When I made it a Local variable in the Sub 'CreateItem' it worked no problem.

    But I have absolutely no idea why!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice