嗨,我是新的委派,我有一个TableView与自定义表格视图单元格包含委托协议。自定义委托ios respondsToSelector不工作自定义表格单元格
当我点击自定义视图单元格的子视图按钮时,它会触发一个事件,该事件会将值传递给我的ViewControllers方法。
TableView位于视图控制器内部。
的customviewcell正常工作时,按一下按钮,它工作正常,但是当它不希望进入状态称为self.delegate respondsToSelector:@selector(btnEditParentLabelText:)
这是我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(不是所有的代码只需要委托的一个)
// 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
这里是我的视图控制器,我实现TablePa rentCellDelegate和包含的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
而且其M档生病只是把一个用于委托方法:
- (void)btnEditParentLabelText:(NSString *)amountParentLabel{
NSLog(@">>> %@", amountParentLabel);
}
有什么错在我的执行?
由于
你设置你的控制器作为该小区的委托? – alex
您是否将委派分配给您的单元格的委托属性? – Jeremy
啊,这就是什么cell.delefat =自我?你能解释为什么你需要这个?它是否在其中实施协议? –