iOS Question ActivityIndicator Use

Discussion in 'iOS Questions' started by RichardN, Sep 28, 2015.

  1. RichardN

    RichardN Active Member Licensed User

    How is this View intended to be used?
    Private ActivityIndicator1 As ActivityIndicator       'Exists in loaded layout
    Private i as int

    'ActivityIndicator1.Visible = False        'Using this method is suggested elsewhere
    ActivityIndicator1.Visible = True

    For i = 0 to 1e6                'Loop many times

    ActivityIndicator1.Visible = 
    This code does not work, the AI does not appear at all. Is there an iOS equivalent of DoEvents ???
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is no DoEvents in B4i.

    What are you doing inside the loop?
  3. RichardN

    RichardN Active Member Licensed User

    The code within the loop looks something like this:

    Sub btnSearch_Click                 

    'Conducts Db wildcard search and sends results as HTML string to 'SearchResults' module
        ActivityIndicator1.Visible = 
    True        'Defn exists in layout and Process_Globals
    Private Events As ResultSet
    Private EventCount As Int
    Private Clue as String = txtClue.Text
    Private Query As String
    Private SearchResult As String
    Private sb As StringBuilder
        Query = 
    "SELECT Event, FromYr, ToYr FROM Events WHERE Event LIKE ? ORDER BY FromYear"
        Events = Main.SQL1.ExecQuery2(Query,
    Array As String("%" & Clue & "%"))
    "<b><font size='5'>Word Search For  '" & Clue & "'</font></b><br><br>")
    Do While Events.NextRow
    Dim Event As String = Events.GetInt("FromYr") & " - " Events.GetInt("ToYr") & ": " & Events.GetString("Event")
            EventCount = EventCount +
    Event  & "<br><br><hr size=2>")
    If EventCount = 0 Then sb.Append("Clue returned no results")
        SearchResult = 
    "<html><body>" & sb.ToString & "</body></html>"
        ActivityIndicator1.Visible = 
        SearchResults.Show (
    "Word Search",SearchResult)     'Module to display the HTML string in  a WebView
    End Sub
    It does seem rather bizarre that the default backcolour for the AI is transparent.... however, getting past that little programmer's trap....

    The database has about 2000 rows and whilst it searches quickly enough on newer devices the search can take 10-15 seconds on an iPhone 4 where the user is faced with a frozen screen for the duration with no AI.

    If I fix a query so as to contrive a longer search period, even on newer devices the AI still does not appear ???
  4. Erel

    Erel Administrator Staff Member Licensed User

    Are you testing the performance in Release mode?

    If it isn't fast enough in release mode then you will need to split the work and use CallSubDelayed to process a smaller chunk each time.
  5. RichardN

    RichardN Active Member Licensed User

    <<Are you testing the performance in Release mode?>> Yes.

    I have taken other measures to slicken up the code that seem to produce better results:

    - Defining the SQL object locally rather than globally then destroying it at the earliest opportunity.
    - Reducing ResultSet.Getxxxx("xxx") calls by using local vars with one call only for each Db field
    - Increasing the required length of the wild-card '%clue%' to return fewer results

    The pause in execution on the slowest test device (iPhone 4) is now acceptable for deployment without an ActivityIndicator for the user to look at.

    .....The lack of ActivityIndicator remains an unsolved mystery!
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that it has any real impact on the performance.

    It is not really a mystery. The UI cannot be updated when the main thread is busy.
  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