iPhone - calling a method from the top view controller
I have 3 viewController classes, A, B and C.
From class A, I push and present class B and then from class B I push and present class C. All classes have delegate protocols defined, so
- b.delegate = a
- c.delegate = b
Now I am inside class C, but I need to run a method from class A.
What is the best way to call that method? I mean the best practice.
I can imagine declaring this on B
- (BOOL) myMethodOnA {
// this method on B will run the method on A and return it to C
return [delegate myMethodOnA];
}
but this sounds to me like a bad soluti开发者_StackOverflow中文版on.
Any suggestions?
thanks.
I might miss something obvious but shouldn't this work?
[c.delegate.delegate myMethodOnA]
Also get into the habit of using accessors (make sure you don't take ownership of delegates). ARC makes this so much better.
Depends on what you want to run on class A.
One easy option is to Observe for a notification in class A and post the notification from class C
Refer: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html
精彩评论