copenndthagen
copenndthagen

Reputation: 50722

call method 2 after method 1 completes

For iphone, can I call method 2 after method 1 completes execution, kind of how we have for animation complete?

Upvotes: 0

Views: 187

Answers (1)

meronix
meronix

Reputation: 6176

asynchronously, i guess... 'couse if not... you have just to call first method1 and then method2...

[self method1];
[self method2]; // will be called just when method1 has ended

but if you need it all working in asynchronously way you can take a look at NSOperationQueue object It's a queue where you can add many methods, it will execute them and you can go on with your code elsewhere... If you add 2 or more methods they will be normally executed togheter (meanwhile), but you can tell the object to execute just 1 method at a time:

NSOperationQueue *aQueue;
aQueue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self 
            selector:@selector(method1) object:nil];
[aQueue addOperation:operation];
[operation release];

[aQueue setMaxConcurrentOperationCount:1]; //tell aQueue to execute just 1 operation at a time

operation = [[NSInvocationOperation alloc] initWithTarget:self 
            selector:@selector(method2) object:nil];
[aQueue addOperation:operation];
[operation release];

luca

Upvotes: 4

Related Questions