我有一个UIStepper
,我在我的programmaticly创建控制UITableViewCell
。 我还创建了一个UILabel
programmaticly的细胞。 发生了什么是步进按压被访问时UILabel
位于不同的小区,即,索引路径1和不为0。这里是代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
//---------UIStepper Creation-------------------//
stepper = [[UIStepper alloc]init];
[stepper setFrame:CGRectMake(220.0f, 65.0f, 0.0f, 0.0f)];
[stepper setTag: indexPath.row];
[stepper addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChanged];
stepperLabel = [[UILabel alloc] init];
[stepperLabel setFrame:CGRectMake(105,70, 20, 20)];
[stepperLabel setTextColor:[UIColor whiteColor]];
[stepperLabel setBackgroundColor:[UIColor clearColor]];
[stepperLabel setTag:stepper.tag];
[stepperLabel setText:[NSString stringWithFormat: @"%d", (int) [stepper value]]];
stepperLabel.lineBreakMode = UILineBreakModeWordWrap;
stepperLabel.numberOfLines = 1;//Dynamic
//Set min and max
[stepper setMinimumValue:0];
[stepper setMaximumValue:4];
// Value wraps around from minimum to maximum
[stepper setWraps:YES];
[stepper setContinuous:NO];
// To change the increment value for each step
...
[cell addSubview:stepperLabel];
[cell addSubview:stepper];
return cell;
这里是我需要的要执行的操作
-(void) stepperPressed:(UIStepper *)sender{
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[sender superview]];
int row = indexPath.row;
NSLog(@"stepper is in row %d",row);
NSLog(@"stepperLabel is in row %d",stepperLabel.tag);
double value = [sender value];
if(sender.tag ==row){
[stepperLabel setText:[NSString stringWithFormat: @"%d", (int) value]];
}
}
认真地需要一些帮助的家伙