I've created a simple example of delegate used. The problem is when i start the application the MyClass class is called and the delegate is sent. But am not able to receive it in ViewController. Below is my code I'd like to know what i did wrong and if am understanding the delegates wrongly.
Apologies for my grammatical mistake. Thank you for helping in advance
MyClass.h
@protocol MyClassDelegate <NSObject>
@required
- (void) myClassDelegateMethod;
@end
@interface MyClass : NSObject
{
id<MyClassDelegate> delegate_;
}
@property( nonatomic, strong ) id<MyClassDelegate> delegate_;
MyClass.m
@synthesize delegate_;
- (id)init
{
if (self = [ super init ] )
{
[ self myMethodDoStuff ];
}
return self;
}
- (void) myMethodDoStuff
{
[ self.delegate_ myClassDelegateMethod ];
}
ViewController.h
#import "MyClass.h"
@interface ViewController : UIViewController< MyClassDelegate >
ViewController.m
-( void ) viewDidLoad
{
[ super viewDidLoad ];
MyClass* class = [ MyClass new ];
[ class setDelegate_:self ];
[ self.view addSubView:class ];
}
The myClassDelegateMethod method in viewController.m is not being called.
-(void)myClassDelegateMethod
{
NSLog( @"Delegates" );
}