ios - 自定义表格单元委托(delegate)

标签 ios objective-c uitableview delegates

我有一个名为 AdminOrderViewController 的 TableView 它有一个名为 StepperProgressCell 的 customcell .

此 customcell 有一个名为 AYStepperView 的自定义 UIView .这个 UIView 中有一个按钮,我在它上面实现了一个委托(delegate),每当它被点击并且我想要这个委托(delegate) clickedAdminOrderViewController 上调用的方法.

但是,我不知道如何添加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];
}

更新:

enter image description here

最佳答案

您需要在 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/

相关文章:

iphone - 每次我的应用程序从后台进入前台时显示 IOS Default.png

ios - 仅使用提供的 IPA 文件更改应用程序版本(无 xcode)

objective-c - 一次运行两个 SKActions

iphone - UIView 在 UITableViewController 的中心

ios - Modal Viewcontoller 覆盖 uiTabBar

ios - NSAutoReleasePool 释放 View Controller ?

iOS Swift - MPCommandCenter & NowPlayingInfoCenter 控制锁屏音乐

objective-c - iPad 开发 : Circular and Linear Gauges

ios - 如何使我的变量可见

iphone - UITableView 中的 moveRowAtIndexPath 导致动画不正确