Hi I'm new to delegation, and what I have is a TableView with a custom table view cell which contains the delegate protocol.
And when I click on the button which is subiew of custom view cell it will fire up an event that will pass a value to my ViewControllers method.
TableView is inside the view controller.
The customviewcell is working properly I even log when the button click and it works fine but when it doesn't want to enter the condition called self.delegate respondsToSelector:@selector(btnEditParentLabelText:)
Here is my customviewcell.h
// ParentTableCell.h
#import <UIKit/UIKit.h>
@protocol ParentTableCellDelegate <NSObject>
@optional
- (void)btnEditParentLabelText:(NSString *)amountParentLabel;
@end
@interface ParentTableCell : UITableViewCell
@property (strong,nonatomic) IBOutlet UITextField *parentLabel;
@property (nonatomic, weak) id <ParentTableCellDelegate>delegate;
-(IBAction)btnEditParentLabel:(id)sender;
@end
customviewcell.m (not all codes just the one needed for delegation)
// ParentTableCell.m
#import "ParentTableCell.h"
-(IBAction)btnEditParentLabel:(id)sender{
NSLog(@"click btn");
if ([self.delegate respondsToSelector:@selector(btnEditParentLabelText:)]) {
NSLog(@"Inside");
[self.delegate btnEditParentLabelText:@"test"];
}
};
@end
Here is my view controller where I implement the TableParentCellDelegate and contains the TableView
// PositionViewController.h
#import <UIKit/UIKit.h>
#import "ParentTableCell.h"
@interface PositionViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate,ParentTableCellDelegate>
{
UIAlertView *addPostionpopup;
}
#define addPositionAlert 1
#define deletePositionAlert 2
@property(nonatomic,strong) IBOutlet UITableView *positionTable;
- (IBAction)btnAddPosition:(id)sender;
@end
And its m file ill just put the method that is used for the delegate:
- (void)btnEditParentLabelText:(NSString *)amountParentLabel{
NSLog(@">>> %@", amountParentLabel);
}
Is there something wrong in my implementation?
Thanks