Reputation: 16793
I have a tableview called AdminOrderViewController
and it has customcell called StepperProgressCell
.
This customcell has a custom UIView called AYStepperView
. There is a button in this UIView and I implemented a delegate on it, whenever it gets clicked and I want to this delegate clicked
method to be called on AdminOrderViewController
.
However, I do not know how to add 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];
}
UPDATE:
Upvotes: 1
Views: 98
Reputation: 20804
You need declare your stteperView as property in your cell.h, your property is declared in the .m and is private, you need to declare in your .h
@interface StepperProgressTableViewCell : UITableViewCell
@property (nonatomic) AYStepperView *stepperView;
@end
After that you can cell.stepperView.delegate= self
in your cellForRow
Hope this helps
Upvotes: 1
Reputation: 124
hide the stepper property in your StepperProgressTableViewCell.m
@interface StepperProgressTableViewCell ()
//@property (nonatomic) AYStepperView *stepperView;
@property (nonatomic) NSUInteger currentIndex;
@property (nonatomic) NSUInteger currentStep;
@property (nonatomic) UIView *containerView;
@end
Move the following property in your StepperProgressTableViewCell.h
and check
@property (nonatomic) AYStepperView *stepperView
then set your delegate to stepperView;
cell.stepperView.delegate = self
Upvotes: 1