I want to have a piece of code.
This, unfortunately, does not make the desired behavior:
- (void) invokeLater_aux:(NSArray*)functionName_arg
{
NSLog(@"invokeLater_aux:" );
if(functionName_arg != nil && (functionName_arg.count > 0 )){
NSString* functionNameString = [functionName_arg objectAtIndex:0];
NSLog(@"functionNameString: %@",functionNameString);
SEL functionName = NSSelectorFromString( functionNameString);
id arg = nil;
if(functionName_arg.count > 1){
arg = [functionName_arg objectAtIndex:1];
}
[self performSelectorOnMainThread:functionName withObject:arg waitUntilDone:YES ];
}
[functionName_arg release];
}
- (void) invokeLater: (SEL)functionName withObject:(id)arg
{
NSLog(@"invoke later: %@",NSStringFromSelector(functionName));
[self performSelectorInBackground:@selector(invokeLater_aux:)
withObject:[[NSArray alloc] initWithObjects:
NSStringFromSelector(functionName),
arg,
nil]
];
}
because it starts a new thread in invokeLater and does not wait for the main thread to complete, and invokeLater_aux will be called in the main thread (when switching context?)
n , n invokeLater.
user529543