2017-08-04 4 views
1

Ich habe eine Tableview AdminOrderViewController genannt und es hat customcell StepperProgressCell genannt.CustomTableCell Delegierter

Diese customcell hat eine benutzerdefinierte UIView AYStepperView genannt. Es gibt eine Schaltfläche in diesem UIView und ich habe einen Delegaten darauf implementiert, wann immer es geklickt wird und ich möchte diese Delegate clicked Methode auf AdminOrderViewController aufgerufen werden.

Aber ich weiß nicht, wie cell.delegate hinzufügen ??

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:

enter image description here

+0

cell.stepperView.delegate = Selbst in Ihrem cellForRow nur wo Sie es kommentiert haben –

+0

Zelle Zugriff nicht auf stepperView ?? – hotspring

+0

, was Sie meinen, bitte erklären Sie sich, wenn Ihre stepperView Eigentum Ihrer Zelle ist, dass Sie dies ohne Probleme tun können, und Ihre steeperView haben eine id Delegat –

Antwort

2

Sie benötigen stteperView als Eigentum in Ihrem cell.h zu erklären, Ihre Immobilie in der .m deklariert und ist privat, müssen Sie in Ihrem .h

StepperProgressTableViewCell.h

erklären
@interface StepperProgressTableViewCell : UITableViewCell 

@property (nonatomic) AYStepperView *stepperView; 

@end 

Danach können Sie cell.stepperView.delegate= self in Ihrem cellForRow

this helps

+0

jede Idee auf https : //stackoverflow.com/questions/45627250/pageviewcontroller-click-event – hotspring

2

verstecken den Schritt Eigenschaft in Ihrem StepperProgressTableViewCell.m

@interface StepperProgressTableViewCell() 

//@property (nonatomic) AYStepperView *stepperView; 
@property (nonatomic) NSUInteger currentIndex; 
@property (nonatomic) NSUInteger currentStep; 
@property (nonatomic) UIView *containerView; 

@end 

Verschieben Sie die folgende Eigenschaft in Ihrem StepperProgressTableViewCell.h und überprüfen

@property (nonatomic) AYStepperView *stepperView 

dann auf stepperView setzen Ihre Stellvertretung;

cell.stepperView.delegate = self 
+0

überprüfen Sie bitte Update. – hotspring

+0

@hotspring - überprüfen Sie die aktualisierte Antwort –

+0

@ Anbu.Karthik, Irgendeine Idee auf dieser https://stackoverflow.com/questions/45499259/pass-cell-section-to-customtablecell?noredirect=1#comment77959329_45499259 – hotspring