在以下自定义表格单元格(StepperProgressTableViewCell
)中,我已将currentSection
硬编码为 2 进行测试,但是当它达到StepperProgressTableViewCell
{{1}时方法,它显示 0 。
TableViewController.m
awakeFromNib
StepperProgressTableViewCell.m
- (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.stepperTableCellDelegate = self;
cell.currentSection = 2;
return cell;
}
AYStepperView.m
@implementation StepperProgressTableViewCell
@synthesize stepperView, currentSection;
- (void)awakeFromNib {
[super awakeFromNib];
[self setUpViews];
// it always shows 0
NSLog(@"%lu", currentSection);
}
- (void)setUpViews {
self.stepperView = [[AYStepperView alloc]initWithFrame:CGRectMake(0, 0 , [[UIScreen mainScreen] bounds].size.width, kFormStepperViewHeight) titles:@[NSLocalizedString(@"Processing", nil), NSLocalizedString(@"Ready", nil), NSLocalizedString(@"Delivered", nil)]];
self.stepperView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
self.stepperView.userInteractionEnabled = YES;
self.stepperView.currentSection = currentSection
[self addSubview:self.stepperView];
}
答案 0 :(得分:2)
您需要添加一个方法来更改此属性,并在实现中将值传递给stepperView
添加类似
的方法-(void)setupCurrentSection:(int)newCurrentSection;
-(void)setupCurrentSection:(int)newCurrentSection{
self.currentSection = newCurrentSection
self.stepperView.currentSection = newCurrentSection
}
在你的cellForRow中然后添加这一行
[cell setupCurrentSection:2];
希望这有帮助