question about performSelectorOnMainThread

Discussion in 'iOS Programming' started by tranvutuan, Jan 12, 2012.

  1. tranvutuan macrumors member

    Joined:
    Dec 19, 2011
    #1
    Hi everyone
    If i have my method A like below :

    Code:
    -(void) myMethodA arg1:myArg1 arg2:myArg2 {
    }

    How can I use performSelectorOnMainThread do invoke myMethodA....I m stuck because right now we have 2 args in method A but the format of performSelectorOnMainThread is
    Code:
    [self performSelectorOnMainThread:<#(SEL)#> withObject:<#(id)#> waitUntilDone:<#(BOOL)#>
     
  2. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #2
    You have two objects that you want to pass to the main thread.

    Create an NSDictionary. Add both of these objects to the dictionary. Assign them keys. Pass the dictionary to the main thread.

    Receive the NSDictionary. Retrieve both objects. Did you remember to define the keys as global variables?

    You could also go to the trouble of creating a custom class that would hold the objects that you want to pass to the main thread.

    Grand Central Dispatch removes all of these problems by letting you capture scope variables with blocks. It is really a much smoother approach.
     
  3. tranvutuan thread starter macrumors member

    Joined:
    Dec 19, 2011
    #3
    Thanks for your help.. I will have it a try
     

Share This Page