Another case of protocol method not being called – NO idea what am I doing wrong here…
Here is the code, omitting unnecessary info…
first header file: AccessNumber.h
@protocol AddItemDelegate <NSObject>
@required
- (void) processSuccessful: (BOOL)success;
@end
@interface AccessNumber : UIViewController <UITableViewDelegate, UITableViewDataSource, ABPeoplePickerNavigationControllerDelegate, UIAlertViewDelegate> {
id <AddItemDelegate> delegate;
}
@property (retain) id <AddItemDelegate> delegate;
@end
first .m file: AccessNumber.m – I am calling the protocol method from viewdidload just for testing purposes, it should basically get called from another method, but same thing for the sake of this convo (tried both of course)
#import "AccessNumber.h"
#import "History.h"
@synthesize delegate;
- (void)viewDidLoad
{
[super viewDidLoad];
....
[[self delegate] processSuccessful:YES];
}
second file header: History.h
@interface History : UIViewController <UITableViewDelegate, UITableViewDataSource, AddItemDelegate> {
....
}
method implementation in history.m
- (void) processSuccessful: (BOOL)success {
NSLog(@"SUCCESS");
}
Appreciate any help. Thanks!
The code seems a little bit funny but you are not telling your “AccessNumber” class who is his delegate, even though you are making the “History” class implement the protocol established by yourself (otherwise you would get a warning).
You have to set the delegate for the “AccessNumber” class like this when setting it up from within “AccessNumber.m”:
or like this when setting it up from within “History.m”: