こんにちは、UITableView があり、UIStepper と UILabel を含むセルを動的に挿入しています。UILabel は UIStepper の値を示します。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(!cell)
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
[cell.textLabel setText:[self.myarray objectAtIndex:indexPath.row]];
UIStepper *stepper = [[UIStepper alloc]init];
UILabel *label = [[UILabel alloc]init];
label.text = [NSString stringWithFormat:@"%.f", stepper.value];
[cell addSubview:stepper];
[cell addSubview:label];
[stepper addTarget:self action:@selector(incrementStepper:) forControlEvents:UIControlEventValueChanged];
return cell;
}
明確にするためにフォーマットを行う上記の行のいくつかを削除しましたが、これは機能し、すべて問題ありません。
-(void)incrementSkillStepper:(id)sender
{
UIStepper *stepper = (UIStepper*)sender;
//set the label that is in the same cell as the stepper with index stepper.value.
}
特定のセルのステッパーをクリックすると、同じセルのラベルをインクリメントしたいのですが、私の問題は addtarget が機能する方法です-この場合はステッパーである送信者のみをイベントに送信できます。動的に作成されたラベルにはアクセスできません。incrementStepper デリゲート メソッドからラベルのテキストを設定する方法を知っている人はいますか?