0

I will start by apologising if this is a naive, simple or stupid question. I am relatively new to objective C and am trying to learn.

Basically I have a situation in which methodA, methodB or methodC are called. These methods then call methodX. Once the end of methodX is reached I need it to re-call the method that called it (methodA, methodB or methodC).

I have never come across this issue before and would like help developing a solution. In a more complex situation I may also have the following. methodA, methodB or methodC are called; they call methodX. methodX goes off and calls a bunch of other methods (that cannot be changed), at some later point methodY(in the same class as methodA, methodB, methodC and methodX) gets called, this in turn should call the method that started out calling methodX (be it methodA, methodB or methodC).

Please can someone point me in the right direction with this problem. If there are any tutorials or basic examples out there that could help I would really appreciate being directed to them. I have tried googling the topic described in my examples however I haven't had much luck since I don't know the technical terms for what I'm trying to achieve.

Thanks in advance.

NOTE: In my examples methodA, methodB, methodC, methodX and methodY are all in the same class.

4

1 回答 1

0

There are two typical ways of doing this.

One way of doing it is to use a delegate. Define a protocol that has a completion method, declare that an object conforms to that protocol, pass that object through to the method, then, when you need to signal completion, call the completion method on that delegate object.

The other way of doing it is to use blocks. Pass a block through to the method, execute it when you are done.

It's also common to see people pass through targets and selectors, or to use notifications. The first two methods are more suited to this type of situation though.

于 2012-05-16T22:07:02.770 回答