First, as @Abizern , try reformatting your code a bit. Use capital letters for classes. Said this is the solution here for your answer.
This is a protocol. I would name it as FirstViewControllerDelegate
, since the class that implements the object is the delegate for FirstViewController
.
#import <Foundation/Foundation.h> @protocol MyProtocol <NSObject> - (void)doSomething; @end
This is a SecondViewController
.
#import <UIKit/UIKit.h> #import "MyProtocol.h" @interface SecondViewController : UIViewController <MyProtocol> @end @implementation SecondViewController // other code here... - (void)doSomething { NSLog(@"Hello FirstViewController"); } @end
This is FirstViewController
.
For completeness, be sure to check out the capabilities of the delegate template. Apple doc is your friend. You can take a look at the-basics-of-protocols-and-delegates to have a basic introduction to the argument. In addition, a SO search allows you to find many answers to this topic.
Hope this helps.
source share