Timing problem

Discussion in 'iOS Programming' started by MACloop, Jan 14, 2010.

  1. MACloop macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #1
    Hello,
    I have an app using NSUrlConnection to connect to the internet and to get some data (XML). When the connection is done I parse the data. In the method parserDidEndDocument I fill a mapView with the data. It works fine. The problem is only that I want to block a segmentedController util the map has its annotations in place. I have set sementedControl.enable = YES at the end of the parser delegate method and have realized this is to sone. The annotations are put on the map (grapically) a bit later. So my question is - where am I after the parser is done? Can I call some delegate method for the view, the map...in order to keep my segmentedControl blocked till the map really is done??

    Any ideas?
    MACloop
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Annoyingly there does not seem to be anything directly useful. I can only suggest that you schedule a method to run a short time later (say after 0.1 seconds) and use the viewForAnnotation: to check if the annotations have views: if they do they should be on screen...
     
  3. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #3
    Thants a good idea! Thanks alot - I will try that out!
    /MACloop
     
  4. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #4
    How do I use a timer in this case? I suppse I should use NSTimer but have not used it before. Do you have a pseudo-code?
    Thanks in advance!
    MACloop
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    If you want to use NSTimer then read the documentation. I don't see how pseudo code will help but here you go:

    Code:
    Add annotations
    Schedule method to run after a short period called checkVisible
    
    checkVisbile:
    Set allVisible to true
    For each annotation
      If the annotation does not have a view set allVisible to false
    End for
    if allVisible is true
      Show the control
    else
      Schedule method to run after a short period called checkVisible
    end if
    
    I suspect what you really want me to post is sample code. I don't post that as I believe it encourages bad habits: not using the documentation, not trying to write your own code first, believing that copy/pasting code is programming and, in general, reducing learning and self reliance.

    I would offer the suggestion that performSelector:withObject:afterDelay: would be better and easier to use than NSTimer.
     
  6. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #6
    Thanks alot and sorry for my bad english. Well, I did not want you to write my code, but give me advice about how to use the timer. I thought a pseudocode would give me a hint of the structure/flow. I will try your advice, instead of the timer. the timer does not seem to work so far. Perhaps have I missed something in the documantation. Again - thanks for your good advice!
    MACloop
     
  7. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany

Share This Page