Search code examples
ios7xcode5

Delegate from ClassD doesn't triggered in ClassA


I have problems about delegate. I have 4 classes, I just name it ClassA, ClassB, ClassC, and ClassD.

In classA, I have a navigationButton next which goes to ClassB and in ClassB I have also a navigationButton next which goes to ClassC and in classC I have also a navigationButton next which goes to classD. Then my problem is that I want my delegate in ClassD will tell classA that operation in ClassD is finish.


Solution

  • Your notion of "delegate" is backwards. What you want is for the ClassA instance to be delegate of the ClassD instance, so that you have a channel for communicating back from the ClassD instance to the classA instance. You can do that by carrying a reference to the classA instance from object to object to object down the chain as it forms, but the simplest way to perform "long-distance" communication of this sort is to use an NSNotification.