如何在目标c中重新加载后更改单元格的值?(How to change value of a cell after reloading in objective c?)

有没有办法在加载后更改单元格的值? 实际上我在表中有一个文本字段,插入相同的值后,我需要对textfield值进行一些数值运算,值计算器需要显示在下一个单元格中的标签上。

那么我怎么能得到相同的结果?任何想法?

提前致谢。

is there any way to change value of a cell after it is loaded? actually i am having one textfield in the table and after inserting the value of the same,i need to do some numeric operations on the textfield value and the value calculater need to display on the lable that in in the next cell.

So how can i get the same result?any idea?

Thanks in advance.

最满意答案

有几种方法可以更新UITableView的单元格。

1)调用表视图方法reloadRowsAtIndexPaths:withRowAnimation: . 这将触发对委托方法tableView:cellForRowAtIndexPath:的调用。 如果您有要更新的数据源,这将是更新单元格的好方法。

NSIndexPath *indexPathOfUpdatedCell = ... [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfUpdatedCell] withRowAnimation:UITableViewRowAnimationFade];

2)也可以直接更新单元。 你可以使用cellForRowAtIndexPath: .

NSIndexPath *indexPathOfUpdatedCell = ... UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPathOfUpdatedCell]; cell.textLabel.text = @"new value";

要为特定行和节创建索引路径,可以使用indexPathForRow:inSection 。

NSUInteger row = ... NSUInteger section = ... NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];

There are several ways to update a cell in a UITableView.

1) Call the table view method reloadRowsAtIndexPaths:withRowAnimation:. This will trigger a call to the delegate method tableView:cellForRowAtIndexPath:. If you have a data source that you are updating this would be a good way to update a cell.

NSIndexPath *indexPathOfUpdatedCell = ... [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfUpdatedCell] withRowAnimation:UITableViewRowAnimationFade];

2) It is also possible to update the cell directly. You can use cellForRowAtIndexPath:.

NSIndexPath *indexPathOfUpdatedCell = ... UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPathOfUpdatedCell]; cell.textLabel.text = @"new value";

To create an index path for a specific row and section it is possible to use indexPathForRow:inSection.

NSUInteger row = ... NSUInteger section = ... NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];如何在目标c中重新加载后更改单元格的值?(How to change value of a cell after reloading in objective c?)

有没有办法在加载后更改单元格的值? 实际上我在表中有一个文本字段,插入相同的值后,我需要对textfield值进行一些数值运算,值计算器需要显示在下一个单元格中的标签上。

那么我怎么能得到相同的结果?任何想法?

提前致谢。

is there any way to change value of a cell after it is loaded? actually i am having one textfield in the table and after inserting the value of the same,i need to do some numeric operations on the textfield value and the value calculater need to display on the lable that in in the next cell.

So how can i get the same result?any idea?

Thanks in advance.

最满意答案

有几种方法可以更新UITableView的单元格。

1)调用表视图方法reloadRowsAtIndexPaths:withRowAnimation: . 这将触发对委托方法tableView:cellForRowAtIndexPath:的调用。 如果您有要更新的数据源,这将是更新单元格的好方法。

NSIndexPath *indexPathOfUpdatedCell = ... [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfUpdatedCell] withRowAnimation:UITableViewRowAnimationFade];

2)也可以直接更新单元。 你可以使用cellForRowAtIndexPath: .

NSIndexPath *indexPathOfUpdatedCell = ... UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPathOfUpdatedCell]; cell.textLabel.text = @"new value";

要为特定行和节创建索引路径,可以使用indexPathForRow:inSection 。

NSUInteger row = ... NSUInteger section = ... NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];

There are several ways to update a cell in a UITableView.

1) Call the table view method reloadRowsAtIndexPaths:withRowAnimation:. This will trigger a call to the delegate method tableView:cellForRowAtIndexPath:. If you have a data source that you are updating this would be a good way to update a cell.

NSIndexPath *indexPathOfUpdatedCell = ... [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfUpdatedCell] withRowAnimation:UITableViewRowAnimationFade];

2) It is also possible to update the cell directly. You can use cellForRowAtIndexPath:.

NSIndexPath *indexPathOfUpdatedCell = ... UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPathOfUpdatedCell]; cell.textLabel.text = @"new value";

To create an index path for a specific row and section it is possible to use indexPathForRow:inSection.

NSUInteger row = ... NSUInteger section = ... NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];