Wait for function to end

Discussion in 'iOS Programming' started by alexbleks, Nov 12, 2010.

  1. alexbleks macrumors newbie

    Joined:
    Apr 22, 2009
    #1
    Hi

    Code:
    - (IBAction) Call1 
    {
      
      for (int i=0; i < 6; i++)
      {
          printf("Processing ID %d", i);
          [self Call2];
      }
    
      printf("User check is completed!");
    }
    
    - (IBAction) Call2
    {
        // Get some user inputs from UI
        
    
    }
    
    
    How can I make "User check is completed!" print after the WHOLE "for" loop has been checked with all the other functions in Call2 before it says "User check completed"?.. Now it rushes through it without waiting for all data to be completed.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Unless Call2 (by the way the convention is to start method names with a lower case letter so that should be call2) is in some way asynchronous then it will work as you want.

    Here's a tip for getting help: post the real, unedited code. What you have above is pointless.
     
  3. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #3
    Break your code up into more methods.

    Put your "User check is completed!" print statement in another method, and call that method from the completion routine of the last data collection method.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    I think, before we suggest anything, we really need to see exactly what happens within Call2, as robbieduncan has already asked for.
     

Share This Page