iOS Question changing colours with a timer. partly works partly doesn't

Discussion in 'iOS Questions' started by Albi, Jun 17, 2015.

  1. Albi

    Albi Active Member Licensed User

    I have this code. It's very strange. I have some textviews which act as buttons. When the user presses them the background changes colour and the text colour also changes. it waits 2 seconds and then loads the next set of buttons, resetting all the colours.
    However, the background ALWAYS changes, and the text colour almost never changes.
    Sub txvQ_Click
    Dim txv As TextView
        txv = 
    Dim theInt As Int
        theInt = txv.Tag
        txv.TextColor = 
        txv.Color = 
        timer2.Enabled = 
    End Sub
    Sub timer2_Tick
        timer2.Enabled = 
    End Sub
    LoadPage 2 is where things get reset. If I take out the resetting of text colour to black, all the text remains white. So it's changing but not showing up. When I step through the code it all works fine.
    What I can't understand is why the background colour changes perfectly, but the textcolour doesn't!?

    I tried changing the order that they occur in this routine, switching it to rgb values to match the .color but it didn't make any difference.

    Also, strangely, the first button press when loading the app always turns the text white. If there are only two 'buttons' loaded, then pressing the second one always turns the text white. Any other 'buttons' pressed only change the background colour.

    Same occurs in debug and release modes.
    Any ideas to try?
  2. klaus

    klaus Expert Licensed User

    Unfortunately you don't give enought information.
    With the two code snippets you posted it's imposible to give a concrete advice !
    What does LoadPage2 do?
  3. Albi

    Albi Active Member Licensed User

    sorry. I was trying to keep it as brief as possible. LoadPage2 loads new questions in this way:
    Sub LoadPage2
    'set answers
        Dim j As Long
    For j = 1 To questionsData.q(currentQ).NoOfAnswers
            lblQuestion.text = questionsData.q(currentQ).getQuestion
            userChoice(j).Visible = 
            userChoice(j).Color = 
            userChoice(j).TextColor = 
            userChoice(j).Text = questionsData.q(currentQ).getAnswers(j-
    End Sub
    The colour parts reset the questions lovely. the textcolour ones do too! (when i comment them out, the textcolour remains white for j in future)
  4. klaus

    klaus Expert Licensed User

    Could you post a small project showing the problem ?
  5. Albi

    Albi Active Member Licensed User

    yes, i've attached as minimal an example as i can.
    the first answer, the text turns white, and backgrounds red. thereafter, just the backgrounds change colour. except when there is a choice of 2 answers, when the second of the two will always turn the text white. very odd indeed.

    (also, please not that restarting the app often throws nullpointerexceptions. I havent worked out why, but cleaning the project and restarting always resolves the issue. I expect that that is something to do with my class, but i don't know what it is yet)

    thanks very much for having a look at this!

    Attached Files:

  6. klaus

    klaus Expert Licensed User

    Sorry for answering only today, but the last days I did some other work.

    I tested your program and see also the strange behaviour.
    I get also the NullPointerExeption, depending on the change of the TextColor. Very strange.
    Changing the color in this line userChoice(j).TextColor = Colors.Black raises the NullPointerExeption.

    I have tried several things with no success.

    I think Erel should have a look at this problem.
  7. Erel

    Erel Administrator Staff Member Licensed User

    I also see the NullPointerException. I will check it.
    klaus likes this.
  8. Albi

    Albi Active Member Licensed User

    thanks both for your help!

    ps I find changing any line which includes my class will cause the null pointer exception
    Last edited: Jun 20, 2015
  9. Erel

    Erel Administrator Staff Member Licensed User

    About the text color. It seems like a bug in iOS. You can workaround it with this code:
    Dim s As String = txv.Text
    txv.Text = 
    txv.Text = s
    The NullPointerException error is fixed for the next update.

    I recommend you to switch to a Map or List instead of an array. It will fix this issue and it will be easier to modify in the future.
  10. Albi

    Albi Active Member Licensed User

    And I'll look at switching the array to a list.
  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