Ios 点击时更改UITableViewCell的值

Ios 点击时更改UITableViewCell的值,ios,objective-c,uitableview,Ios,Objective C,Uitableview,当用户点击时,我需要更改UITableViewCell中的值 我需要通过UITableViewCell中的值的动画来修改该值 现在,当用户点击UILabel时,我实现了一个UIAppgestureRecognitizer,如下所示: UITapGestureRecognizer *tapOnAmount = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnBalance)]; [cell.amou

当用户点击时,我需要更改
UITableViewCell
中的值

我需要通过
UITableViewCell
中的值的动画来修改该值

现在,当用户点击
UILabel
时,我实现了一个
UIAppgestureRecognitizer
,如下所示:

UITapGestureRecognizer *tapOnAmount = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnBalance)];
[cell.amountLabel setUserInteractionEnabled:YES];
[cell.amountLabel addGestureRecognizer:tapOnAmount];
更改方法
didTapOnBalance
中的值将使应用程序崩溃,如下所示:

-(void)tapOnBalance{
    NSString *headerIdentifier = @"HeaderCell";
    HeaderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:headerIdentifier];
    cell.amountLabel.text = @"new Value"; // this will crash because at runtime
    // the compiler won't recognize cell.amountLabel...
}

UITableViewCell
中实现此操作将导致我将
HeaderTableViewCell
的值发送到子类,我也不知道如何执行此操作。

您必须实现didSelecRowAtIndexPath,并在更改值后在其中写入以下代码行以设置被点击行的动画

[self.myTableView reloadRowsAtIndexPaths:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 

希望有帮助

您必须实现didSelecRowAtIndexPath,并在更改值后在其中写入以下代码行以设置被点击行的动画

[self.myTableView reloadRowsAtIndexPaths:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 

希望有帮助

您必须实现didSelecRowAtIndexPath,并在更改值后在其中写入以下代码行以设置被点击行的动画

[self.myTableView reloadRowsAtIndexPaths:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 

希望有帮助

您必须实现didSelecRowAtIndexPath,并在更改值后在其中写入以下代码行以设置被点击行的动画

[self.myTableView reloadRowsAtIndexPaths:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 

希望有帮助

您的代码完全错误

当用户点击现有单元格并试图更改新单元格中显示的值时,您正在创建一个新单元格。不要那样做


相反,请更改表视图数据模型中的数据,然后告诉表视图重新加载该单元格(如ZAZ的回答中所述)。如果您已更改数据模型以反映单元格的新信息,则重新加载将导致其显示为新设置。

您的代码完全错误

当用户点击现有单元格并试图更改新单元格中显示的值时,您正在创建一个新单元格。不要那样做


相反,请更改表视图数据模型中的数据,然后告诉表视图重新加载该单元格(如ZAZ的回答中所述)。如果您已更改数据模型以反映单元格的新信息,则重新加载将导致其显示为新设置。

您的代码完全错误

当用户点击现有单元格并试图更改新单元格中显示的值时,您正在创建一个新单元格。不要那样做


相反,请更改表视图数据模型中的数据,然后告诉表视图重新加载该单元格(如ZAZ的回答中所述)。如果您已更改数据模型以反映单元格的新信息,则重新加载将导致其显示为新设置。

您的代码完全错误

当用户点击现有单元格并试图更改新单元格中显示的值时,您正在创建一个新单元格。不要那样做


相反,请更改表视图数据模型中的数据,然后告诉表视图重新加载该单元格(如ZAZ的回答中所述)。如果您已更改数据模型以反映单元格的新信息,则重新加载数据将使其显示新设置。

您不能只取消新单元格的定义,这不会给你用户点击的单元格-它会生成一个新的。但是,如果您稍微更改点击处理程序,就可以从手势中获得点击单元格的索引路径

您需要稍微更改手势的初始化(查看选择器):

然后对你的处理程序进行另一个轻微的更改:

- (void)tapOnBalance:(UITapGestureRecognizer *)sender
{
    CGPoint location = [sender locationInView:self.view];
    CGPoint locationInTableview = [self.tableView convertPoint:location fromView:self.view];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:locationInTableview];

    // then you can either use the index path to call something like configureCell or send a didSelectRowAtIndexPath like this:
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}

你不能只是去定义一个新的单元格,它不会给你用户点击的单元格——它会创建一个新的单元格。但是,如果您稍微更改点击处理程序,就可以从手势中获得点击单元格的索引路径

您需要稍微更改手势的初始化(查看选择器):

然后对你的处理程序进行另一个轻微的更改:

- (void)tapOnBalance:(UITapGestureRecognizer *)sender
{
    CGPoint location = [sender locationInView:self.view];
    CGPoint locationInTableview = [self.tableView convertPoint:location fromView:self.view];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:locationInTableview];

    // then you can either use the index path to call something like configureCell or send a didSelectRowAtIndexPath like this:
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}

你不能只是去定义一个新的单元格,它不会给你用户点击的单元格——它会创建一个新的单元格。但是,如果您稍微更改点击处理程序,就可以从手势中获得点击单元格的索引路径

您需要稍微更改手势的初始化(查看选择器):

然后对你的处理程序进行另一个轻微的更改:

- (void)tapOnBalance:(UITapGestureRecognizer *)sender
{
    CGPoint location = [sender locationInView:self.view];
    CGPoint locationInTableview = [self.tableView convertPoint:location fromView:self.view];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:locationInTableview];

    // then you can either use the index path to call something like configureCell or send a didSelectRowAtIndexPath like this:
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}

你不能只是去定义一个新的单元格,它不会给你用户点击的单元格——它会创建一个新的单元格。但是,如果您稍微更改点击处理程序,就可以从手势中获得点击单元格的索引路径

您需要稍微更改手势的初始化(查看选择器):

然后对你的处理程序进行另一个轻微的更改:

- (void)tapOnBalance:(UITapGestureRecognizer *)sender
{
    CGPoint location = [sender locationInView:self.view];
    CGPoint locationInTableview = [self.tableView convertPoint:location fromView:self.view];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:locationInTableview];

    // then you can either use the index path to call something like configureCell or send a didSelectRowAtIndexPath like this:
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}

谢谢不幸的是,我不能调用
indepath
,因为它在任何委托方法之外。就在
tapOnBalance
方法的内部。你有没有子类uitableview?谢谢!不幸的是,我不能调用
indepath
,因为它在任何委托方法之外。就在
tapOnBalance
方法的内部。你有没有子类uitableview?谢谢!不幸的是,我不能调用
indepath
,因为它在任何委托方法之外。就在
tapOnBalance
方法的内部。你有没有子类uitableview?谢谢!不幸的是,我不能调用
indepath
,因为它在任何委托方法之外。就在
tapOnBalance
方法的内部。你有没有子类uitableview?谢谢!如何更改事件(如轻敲)数据模型中的数据?谢谢!如何更改事件(如轻敲)数据模型中的数据?谢谢!如何更改事件(如轻敲)数据模型中的数据?谢谢!如何在一个事件(如轻敲)中更改数据模型中的数据?这看起来很不错:)等等,我会马上尝试实现它,我可以帮忙的!:)这看起来很不错:)等等,我会马上尝试实现的,我可以帮忙的!:)这看起来很不错:)等等,我会马上尝试实现的,我可以帮忙的!:)看起来不错:)等一下,我会的