Ios 在动态表视图中管理多个步进器时遇到问题
所以我有一个动态列表,每个cel包含一个步进器和一个带有不同标签的标签。当我使用步进器时,标签必须刷新到步进器的值。问题是(我认为)发送方发送了错误的值,或者(从其他单元格)获取了另一个步进器的值。例如,有时我点击单元格[0]上的步进器,其值会随着标签的变化而变化,但当我按下单元格[1]的步进器时,它会获取之前点击的步进器的值并刷新其值,而不是添加1(在步进器中输入)。。。有时候它会说不谢谢你我会做我想做的任何事情哈哈,这是完成清单的代码Ios 在动态表视图中管理多个步进器时遇到问题,ios,cocoa-touch,tableview,Ios,Cocoa Touch,Tableview,所以我有一个动态列表,每个cel包含一个步进器和一个带有不同标签的标签。当我使用步进器时,标签必须刷新到步进器的值。问题是(我认为)发送方发送了错误的值,或者(从其他单元格)获取了另一个步进器的值。例如,有时我点击单元格[0]上的步进器,其值会随着标签的变化而变化,但当我按下单元格[1]的步进器时,它会获取之前点击的步进器的值并刷新其值,而不是添加1(在步进器中输入)。。。有时候它会说不谢谢你我会做我想做的任何事情哈哈,这是完成清单的代码 -(UITableViewCell *)tableVie
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellOrder" forIndexPath:indexPath];
UILabel *cantidad = (UILabel*)[cell viewWithTag:2];
UILabel *precio = (UILabel*)[cell viewWithTag:3];
UILabel *nombre = (UILabel*)[cell viewWithTag:4];
UIStepper *stepper = (UIStepper*) [cell viewWithTag:5];
PFObject *object = [self.myOrder objectAtIndex:indexPath.row];
cantidad.text = [NSString stringWithFormat:@"%.0f", stepper.value];
precio.text = [NSString stringWithFormat:@"%d",([[object objectForKey:@"precio"] intValue] * [cantidad.text intValue])];
nombre.text = [object objectForKey:@"nombre"];
PFImageView *image = (PFImageView *)[cell viewWithTag:1];
image.file = [object objectForKey:@"imagen"];
[image loadInBackground];
[self.mailEnviar addObject:precio.text];
return cell;
}
var cantidad是我需要刷新的标签
所以我的刷新代码是这个
- (IBAction)valueChanged:(UIStepper *)sender
{
UIView *view = [sender superview]; //to recover the superview
self.selectedCell = (UITableViewCell *) [[view superview] superview]; //this is making a cast to get the cell of the stepper (the one that was pressed)
NSIndexPath *indexPath = [self.tableView indexPathForCell:self.selectedCell ]; // to get the index path and help me refresh that cell in specific
self.selectedRow = [[NSArray alloc]initWithObjects:indexPath, nil];
[self.tableView reloadRowsAtIndexPaths:self.selectedRow withRowAnimation:UITableViewRowAnimationAutomatic]; // to refresh the selected cell
}
希望你能帮助我 通常,当您有一个表视图时,您应该在该表视图的数据模型中进行更改。所以,当点击stepper时,您需要更新的不是标签,而是数据源,然后要求table重新加载这样的单元格
因此,您需要在对象数组中保存每个步进器值,在
valueChanged
方法中更新该值,然后重新加载单元格(您已经这样做了)。不清楚如何为每个步进器添加操作以调用valueChanged
函数。嗯。。。这些是我用来进行更新的唯一方法。。。步进器连接到valueChanged方法,因此任何时候点击步进器,该方法都会执行重新加载行…抱歉。。。打字介绍哈哈。。。然后,它刷新了点击步进器的单元。现在所述步进器包含新值ok。。。然后,通过表格的构建方式(第一种方法),它会将我的标签刷新到新的步进值,这就是我现在正在做的。。。如果我误解了,请纠正我。。。你是说我需要给每个步进器添加一个特定的动作?我认为这是不可能的,因为这是一个动态表。您是否在InterfaceBuilder中将stepper附加到其动作?那么我是否需要为我创建的每个单元格设置一个值数组?