我有一个名为 AdminOrderViewController
的 TableView 它有一个名为 StepperProgressCell
的 customcell .
此 customcell 有一个名为 AYStepperView
的自定义 UIView .这个 UIView 中有一个按钮,我在它上面实现了一个委托(delegate),每当它被点击并且我想要这个委托(delegate) clicked
在 AdminOrderViewController
上调用的方法.
但是,我不知道如何添加cell.delegate??
AdminOrderViewController.m
@interface AdminOrderViewController : UIViewController <AYStepperViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"StepperProgressCell";
StepperProgressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[StepperProgressTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
//cell.stepperView.delegate= ???
return cell;
}
- (void)clicked
{
// is not getting called?
}
StepperProgressTableViewCell.m
@interface StepperProgressTableViewCell ()
@property (nonatomic) AYStepperView *stepperView;
@property (nonatomic) NSUInteger currentIndex;
@property (nonatomic) NSUInteger currentStep;
@property (nonatomic) UIView *containerView;
@end
@implementation StepperProgressTableViewCell
@synthesize stepperView;
- (void)awakeFromNib {
[super awakeFromNib];
[self setUpViews];
}
- (void)setUpViews {
self.stepperView = [[AYStepperView alloc]initWithFrame:CGRectMake(0, 0 , [[UIScreen mainScreen] bounds].size.width, kFormStepperViewHeight) titles:@[@"Processing",@"Ready",@"Delivered", nil)]];
[self addSubview:self.stepperView];
}
AYStepperView.m
@protocol AYStepperViewDelegate <NSObject>
@required
- (void)clicked;
@end
- (void)buttonPressed:(UIButton *)sender {
[stepperDelegate clicked];
}
更新:
最佳答案
您需要在 cell.h 中将您的 stteperView 声明为属性,您的属性在 .m 中声明并且是私有(private)的,您需要在 .h 中声明
StepperProgressTableViewCell.h
@interface StepperProgressTableViewCell : UITableViewCell
@property (nonatomic) AYStepperView *stepperView;
@end
之后你可以cell.stepperView.delegate= self
在你的 cellForRow希望这可以帮助
关于ios - 自定义表格单元委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45498416/