custom delegate ios respondsToSelector not working custom table cell
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 the
button in the custom view cell it will fire up an event that will pass its
value to my View Controller Which contains the TableView.
The customviewcell is working properly I even log when the btn is click
and it works but when it got to the condition self.delegate
respondsToSelector:@selector(btnEditParentLabelText:) it doesn't go
through.
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 ;D
No comments:
Post a Comment