0
I am implementing a protocol but the same is not able to make the call from delegate
:
if ([self.delegate respondsToSelector:@selector(addCard)]) {
[self.delegate addCard];
}
Viewcontroller. m
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@protocol ViewControllerDelegate <NSObject>
-(void)addCard;
@end
@interface ViewController : UIViewController{
}
@property (nonatomic, weak) id <ViewControllerDelegate> delegate;
- (IBAction)setCard:(id)sender;
@end
#import "ViewController.h"
#import "PSWallet.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize delegate;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)setCard:(id)sender {
if ([self.delegate respondsToSelector:@selector(addCard)]) {
[self.delegate addCard];
}
}
@end
Pswallet. m
#import <Foundation/Foundation.h>
#import "ViewController.h"
@interface PSWallet : NSObject<ViewControllerDelegate>
@end
#import "PSWallet.h"
@interface PSWallet ()
@end
@implementation PSWallet
-(void)addCard{
NSLog(@"not work");
}
@end